I am new to Woocommerce. I was trying to show the quantity box in the shop page. I have used the below code and it\'s working as expected:
add_action( \'woo
Does everything as above, without the "quantity bug".
The code:
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_loop_ajax_add_to_cart', 10, 2 );
function quantity_inputs_for_loop_ajax_add_to_cart( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
// Get the necessary classes
$class = implode( ' ', array_filter( array(
'button',
'product_type_' . $product->get_type(),
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',
) ) );
// Adding embeding '
);
}
return $html;
}
add_action( 'wp_footer' , 'archives_quantity_fields_script' );
function archives_quantity_fields_script(){
//if( is_shop() || is_product_category() || is_product_tag() ): ?>
References:
@LoicTheAztec's entry above 11 Feb 2018.
@braciawrite's and @andrewmclagan's GitHub entries on 11 Dec 2015 and 15 Mar 2018 respectively.
https://gist.github.com/webaware/6260326
Note:
Code should perform the check when "add_to_cart" button is pressed, not on quantity change.
I've commented out the if and endif statements under function "archives_quantity_fields_script" as I am running this code on a custom page with WooCommerce products.
Hope this helps!