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