Variable product ajax_add_to_cart fix.

Ensure simple products still use the class ajax_add_to_cart but not have them interfere with Variable products. Fixes the issue where hitting "Select options" on a variable product from the archive-product.php template adds them straight to cart.
This commit is contained in:
Jason King 2017-09-16 13:51:02 +09:30 committed by GitHub
parent 10f5e9212e
commit 088a89a36a
1 changed files with 5 additions and 4 deletions

View File

@ -19,15 +19,16 @@
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
global $product; global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link', echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="add_to_cart_button ajax_add_to_cart btn btn-outline-primary btn-block">%s</a>', sprintf( '<div class="add-to-cart-container"><a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="%s product_type_%s single_add_to_cart_button btn btn-outline-primary btn-block %s"> %s</a></div>',
esc_url( $product->add_to_cart_url() ), esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $quantity ) ? $quantity : 1 ),
esc_attr( $product->get_id() ), esc_attr( $product->get_id() ),
esc_attr( $product->get_sku() ), esc_attr( $product->get_sku() ),
esc_attr( isset( $quantity ) ? $quantity : 1 ),
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
esc_attr( $product->get_type() ),
$product->get_type() == 'simple' ? 'ajax_add_to_cart' : '',
esc_html( $product->add_to_cart_text() ) esc_html( $product->add_to_cart_text() )
), ),
$product ); $product );