Archived topic
WooCommerce plus minus buttons on categories/loop
1 reply · Started by Carlos on July 14, 2022
Hi, I use GeneratePress Pro and I have enables plus minus buttons that show nice on single products, but in the loop I see the Add to cart button, and I'd like to change to the plus/minus and quantity with a cart button. There is an option or code for this? I see a class do-quantity-buttons on the li element inside the loop, but not quantity buttons.
Kindly regards, Carlos Longarela.
Oh, I fixed it showing the woocommerce_quantity_input with this code:
/**
* Override loop template and show quantities next to add to cart buttons.
*
* @param string $html HTML of the add to cart button.
* @param object $product Product object.
*
* @return string
*/
function cl_woo_quantity_inputs_loop( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() ) {
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false );
$html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
$html .= '</form>';
}
return $html;
}
add_filter( 'woocommerce_loop_add_to_cart_link', 'cl_woo_quantity_inputs_loop', 10, 2 );