Automattic\WooCommerce\Blocks\BlockTypes

AbstractProductGrid::get_add_to_cart()protectedWC 1.0

Get the "add to cart" button.

Метод класса: AbstractProductGrid{}

Хуков нет.

Возвращает

Строку. Rendered product output.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_add_to_cart( $product );
$product(\WC_Product) (обязательный)
Product.

Код AbstractProductGrid::get_add_to_cart() WC 7.7.0

protected function get_add_to_cart( $product ) {
	$attributes = array(
		'aria-label'       => $product->add_to_cart_description(),
		'data-quantity'    => '1',
		'data-product_id'  => $product->get_id(),
		'data-product_sku' => $product->get_sku(),
		'rel'              => 'nofollow',
		'class'            => 'wp-block-button__link ' . ( function_exists( 'wc_wp_theme_get_element_class_name' ) ? wc_wp_theme_get_element_class_name( 'button' ) : '' ) . ' add_to_cart_button',
	);

	if (
		$product->supports( 'ajax_add_to_cart' ) &&
		$product->is_purchasable() &&
		( $product->is_in_stock() || $product->backorders_allowed() )
	) {
		$attributes['class'] .= ' ajax_add_to_cart';
	}

	return sprintf(
		'<a href="%s" %s>%s</a>',
		esc_url( $product->add_to_cart_url() ),
		wc_implode_html_attributes( $attributes ),
		esc_html( $product->add_to_cart_text() )
	);
}