Skip Navigation

[Resolved] woocommerce-notices-wrapper on Woocommerce single product template

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.95 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 5 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1327575

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.

#1327793

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.

#1329013

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.

#1329097

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