Home › Forums › WoodMart support forum › woocommerce notices not displaying
woocommerce notices not displaying
- This topic has 5 replies, 2 voices, and was last updated 1 year, 10 months ago by Luke Nielsen.
-
AuthorPosts
-
February 8, 2023 at 2:13 am #441215
fred-3577ParticipantI had to do some custom validation during an add to cart process. If the process needs to be stopped I try to do a wc_add_notice to notify the customer I stopped them from adding the item to the cart. The function does successfully do what it is supposed to but the notices do not appear.
function check_for_samples( $passed, $product_id, $quantity ) { global $woocommerce; if(has_term( 8484, 'product_cat', $product_id )) { if($quantity > 4) { wc_add_notice('Sorry You can only order up to 4 of sample SKU.', 'error' ); $passed = false; } else { $total_sample_count = 0; $total_this_sample_count = 0; foreach( WC()->cart->get_cart() as $cart_item ) { if(has_term( 8484, 'product_cat', $cart_item['product_id'] )) { if($product_id == $cart_item['product_id']) { $total_this_sample_count = $cart_item['quantity']; $total_sample_count += $cart_item['quantity']; } else { $total_sample_count += $cart_item['quantity']; } } } if($total_this_sample_count + $quantity > 4) { wc_add_notice('Sorry You can only order up to 4 of sample SKU.', 'error' ); $passed = false; } else if( $total_sample_count + $quantity > 6 ) { wc_add_notice('Sorry You can only order up to 6 samples.', 'error' ); $passed = false; } } } wc_print_notices(); return $passed; } add_filter( 'woocommerce_add_to_cart_validation', 'check_for_samples', 10, 3 );
February 8, 2023 at 10:46 am #441305
Luke NielsenKeymasterHello,
Unfortunately, such customization is not included in our support.
You can get acquainted with Envato Support Policy here:
https://themeforest.net/page/item_support_policy
I do hope you would remain as our valued customer and thank you for your time.
Kind Regards
February 8, 2023 at 5:53 pm #441453
fred-3577ParticipantThis is a function I already use. I only need to know why the wc_add_notice function does not work with your theme??
February 9, 2023 at 1:11 pm #441714
Luke NielsenKeymasterHello,
The
wc_add_notice
function is related to WooComemrce so first check how it works on the default Storefront theme, just to understand whether our theme issue is or not.Kind Regards
February 9, 2023 at 6:54 pm #441845
fred-3577ParticipantYes it works in storefront. Please try it in a testing environment of your own and see if the same
- This reply was modified 1 year, 10 months ago by fred-3577.
February 13, 2023 at 10:33 am #442472
Luke NielsenKeymasterHello,
I apologize for the delay.
On my side, the
wc_add_notice
function works well: https://prnt.sc/nZj5SKcJhcSbLet me know if there is anything else I can help and have a good day!
Kind Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register