Automattic\WooCommerce\Blocks\BlockTypes
AbstractProductGrid::get_add_to_cart() protected WC 1.0
Get the "add to cart" button.
{} It's a method of the class: AbstractProductGrid{}
No Hooks.
Return
String. Rendered product output.
Usage
// protected - for code of main (parent) or child class $result = $this->get_add_to_cart( $product );
- $product(\WC_Product) (required)
- Product.
Code of AbstractProductGrid::get_add_to_cart() AbstractProductGrid::get add to cart WC 5.0.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 add_to_cart_button',
);
if ( $product->supports( 'ajax_add_to_cart' ) ) {
$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() )
);
}