April 17, 2023 at 7:14 am
I have added the following function to display quantities next to Add to cart buttons:
/**
* Override loop template and show quantities next to add to cart buttons
*/
add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘quantity_inputs_for_woocommerce_loop_add_to_cart_link’, 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
if ( $product && $product->is_type( ‘simple’ ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$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;
}
However I now have two issues.
1. Is there any way to display the quantity selector and Add to carton button on one line which I think will look tidier?
2. From a search result page, if an item is added to cart, the site redirects to the home page. For example, search ‘peony’, add an item to the cart directly from search results page.
The site is B2B so a customer login is required to see the fields
[login details added to a private reply]
-
This topic was modified 2 years, 9 months ago by
Karla.