From 088a89a36abf515a5c4f12d0a223302a02b5f18e Mon Sep 17 00:00:00 2001 From: Jason King Date: Sat, 16 Sep 2017 13:51:02 +0930 Subject: [PATCH] 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. --- woocommerce/loop/add-to-cart.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/woocommerce/loop/add-to-cart.php b/woocommerce/loop/add-to-cart.php index 4b1dc60..d6dada2 100644 --- a/woocommerce/loop/add-to-cart.php +++ b/woocommerce/loop/add-to-cart.php @@ -19,15 +19,16 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } - global $product; - echo apply_filters( 'woocommerce_loop_add_to_cart_link', - sprintf( '%s', + sprintf( '
%s
', esc_url( $product->add_to_cart_url() ), - esc_attr( isset( $quantity ) ? $quantity : 1 ), esc_attr( $product->get_id() ), 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() ) ), $product );