Home Forums WoodMart support forum woocommerce notices not displaying

woocommerce notices not displaying

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #441215

    fred-3577
    Participant

    I 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 );
    
    
    #441305

    Luke Nielsen
    Keymaster

    Hello,

    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

    #441453

    fred-3577
    Participant

    This is a function I already use. I only need to know why the wc_add_notice function does not work with your theme??

    #441714

    Luke Nielsen
    Keymaster

    Hello,

    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

    #441845

    fred-3577
    Participant

    Yes 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, 7 months ago by fred-3577.
    #442472

    Luke Nielsen
    Keymaster

    Hello,

    I apologize for the delay.

    On my side, the wc_add_noticefunction works well: https://prnt.sc/nZj5SKcJhcSb

    https://prnt.sc/e17dsLU3a3AB

    Let me know if there is anything else I can help and have a good day!

    Kind Regards

Viewing 6 posts - 1 through 6 (of 6 total)