product_type, array('variable', 'grouped', 'external'))) { // only if can be purchased if ($product->is_purchasable()) { // show qty +/- with button ob_start(); woocommerce_simple_add_to_cart(); $button = ob_get_clean(); // modify button so that AJAX add-to-cart script finds it $replacement = sprintf('data-product_id="%d" data-quantity="1" $1 ajax_add_to_cart add_to_cart_button product_type_simple ', $product->id); $button = preg_replace('/(class="single_add_to_cart_button)/', $replacement, $button); } } return $button; } /** * add the required JavaScript */ function custom_woo_after_shop_loop() { ?>