This topic has 4 replies, 3 voices, and was last updated 7 months, 1 weeks ago ago by Andrew Mitchell
Dear 8Theme team,
I suspect an issue with the wc_add_notice(…, ‘error’) on the theme.
I am trying to get the cart / checkout display an error if a minimum order quantity is not reached.
I tried two ways:
– Snippet:
add_action(‘woocommerce_check_cart_items’, ‘minimum_item_quantity_by_category’);
function minimum_item_quantity_by_category(){
// Your categories settings (count initialized to zero for each)
$terms_count = [’16 Avril 2024′ => 0];
// Loop through cart items
foreach ( WC()->cart->get_cart() as $item ) {
// Loop through categories
foreach ( array_keys($terms_count) as $category ) {
if ( has_term( $category, ‘product_cat’, $item[‘product_id’]) ) {
$terms_count[$category] += $item[‘quantity’];
}
}
}
// Loop through category / count array
foreach ( $terms_count as $category => $count ) {
if ( $count != 0 && $count < 3 ) {
$term = get_term_by('name', $category, 'product_cat');
wc_add_notice('error message', 'error');
}
}
}
Last wc_add_notice 'error' call, if you change to 'notice', it will work (but it will not "block" the order). If you do not change, I end up on a page saying there is an issue with the products in the cart (not displaying the error message...)
- Use third-party "Minimum and Maximum Quantity for WooCommerce" (https://wordpress.org/plugins/min-and-max-quantity-for-woocommerce/). When setting the Min order qty, nothing happens (suspecting the wc_add_notice error is not functional). (see screenshot)
Unfortunately, I'm working on local, so I'll be unable to provide access to my working version. It is quite bare though in terms of extensions.
Any idea?
Thanks,
Solène
Btw, some lead:
the elementor XStore default cart page seems the one faulty, see compared to the standard elementor one !
Dear Chiche Solene,
We kindly request that you attempt to utilize the following hook:
add_action( 'woocommerce_before_cart_table', 'required_min_cart_subtotal_amount', 99 );
Please inform us of the outcome at your earliest convenience.
Warm regards,
The 8Theme Team
Dear Chiche Solene,
We trust our theme is enhancing your experience. Taking a brief moment to rate it with a glowing 5 stars on ThemeForest would be immensely appreciated. Your feedback holds significant value for us.
Click here to rate now: https://themeforest.net/downloads
Thank you sincerely for your ongoing support!
Best Regards,
The 8Theme Team
The issue related to '‘Suspecting faulty wc_add_notice behavior’' has been successfully resolved, and the topic is now closed for further responses