If there is an error adding to cart, the single product page reloads but does not display woocommerce-notices-wrapper.
Have tried adding <div class="woocommerce-notices-wrapper"></div> to the top of the template, but this did not work.
Thanks in advance.
Hello,
Please try the shortcode [wpv-add-to-cart-message], see our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-add-to-cart-message
This shortcode displays a success message when a product is added to the cart.
Please note that there is an extra step involved if you want to use the wpv-add-to-cart-message on the product listing pages. Go to the WooCommerce -> Settings page, click the Products tab and then the Display tab. There, uncheck the Enable AJAX add to cart buttons on archives option. This is needed because a page refresh is required for WooCommerce “Add to cart” message to work.
Hiya,
It's not the add the cart we need, it's any error messages.
We want to restrict the number of items a user can purchase.
In functions.php we have
if( $cart_items_count >= 10 || $total_count > 10 ){
$passed = false;
wc_add_notice( __( "You can’t have more than 10 items in the basket", "woocommerce" ), "error" );
}
However the message does not display on the woo-commerce template, even after adding [wpv-add-to-cart-message] shortcode.
Thanks for the details, there isn't such kind of built-in feature within Toolset WooCommerce Views plugin, [wpv-add-to-cart-message] can only display the message, it can not restrict the number of items in cart.
I suggest you try Woocommerce filters "woocommerce_add_to_cart_validation" to change the error message, for example:
add_filter( 'woocommerce_add_to_cart_validation', 'items_allowed_add_to_cart', 10, 3 );
function items_allowed_add_to_cart( $passed, $product_id, $quantity ) {
$cart_items_count = WC()->cart->get_cart_contents_count();
$total_count = $cart_items_count + $quantity;
if( $cart_items_count >= 10 || $total_count > 10 ){
// Set to false
$passed = false;
// Display a message
wc_add_notice( __( "You can't have more than 10 items in the basket", "woocommerce" ), "error" );
}
return $passed;
}
It should be able to display error message "You can’t have more than 10 items in the basket" insider [wpv-add-to-cart-message] shortcode too.
See similar thread here:
https://stackoverflow.com/questions/46007102/limit-the-number-of-cart-items-in-woocommerce