Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    You could dequeue the script, but not sure why you’d need to?

    Thread Starter Roman159

    (@roman159)

    Hi,
    I just tried to dequeue the script like

    wp_dequeue_script( ‘wc-cart’ );

    It works fine for cart update but it has other side effect. The shipping calculator does not work.

    I want that functionality because I got custom cart item listing dropdown on the header of the page. While updating the cart items, the cart item on header does not get updated unless the page reload.

    Thanks

    Plugin Contributor Mike Jolley

    (@mikejolley)

    So in it’s place you’ll need your own javascript which has the shipping calc code, but not the cart update code. This is all in our cart.js.

    @roman159 / @mikejolley

    I am in the need for a similar solution so please see if you could shed some light on this. We display some extra items on the cart page which we’ve added using an action hook. The maximum number of those items per order depends on the total of other items in cart so when customers add more than the maximum number of items, we display an error message and disable to proceed to checkout button. However, as the Ajax cart only reloads everything within ‘shop table’ and ‘cart collaterals’ section, it doesn’t display our error messages. Could you kindly explain how to reload the entire ‘content-area’ div so it would display the error messages too?

    Many thanks in advance.

    • This reply was modified 8 years, 5 months ago by Pradeep.
    Plugin Contributor Mike Jolley

    (@mikejolley)

    If errors are added early enough and in the correct place it will render those for you.

    @mikejolley,

    Thanks for the quick response. Is the fact that it does everything else an indication for that we add the errors early enough? I’ve copied that part of the code below (go easy on me as my PHP skills aren’t the best).

        add_action( 'woocommerce_check_cart_items', 'check_total' );
        function check_total() {
            // Only run on Cart or Checkout pages
            
            if( is_cart() || is_checkout() ) {
                global $woocommerce, $product;
                $total_quantity = 0; //meals
                $total_squantity = 0; //snacks 
                $display_notice = 1;
                $i = 0;
                // Set up the acceptable meal totals.
                $acceptable_totals = array(8, 9, 10, 11, 12, 20, 21, 22, 23, 24);
    			
                //loop through all cart products
                foreach ( $woocommerce->cart->cart_contents as $product ) {
                    // See if any product is from the breakfast or meals category or not
                    
                    if ( has_term( 'fitmeals', 'product_cat', $product['product_id'] ) || has_term( 'fitbreakfast', 'product_cat', $product['product_id'] ) ) {
                        $total_quantity += $product['quantity'];
                    }
           
                    if ( has_term( 'fitsnacks', 'product_cat', $product['product_id'] )) {
                        $total_squantity += $product['quantity'];
                    }
                }
    
                foreach($acceptable_totals as $total_check) {               
                    if ( $total_check == $total_quantity ) {
                        $display_notice = 0;
                    }
                }
    
                foreach ( $woocommerce->cart->cart_contents as $product ) {
                    
                    if ( has_term( 'fitmeals', 'product_cat', $product['product_id'] ) || has_term( 'fitbreakfast', 'product_cat', $product['product_id'] ) ) {
                        
                        if( $display_notice == 1 && $i == 0 ) {
                            // Display error message
                            wc_print_notice( sprintf( 'Whoa there, you need to order 8-12 meals (1 cooler) or 20-24 meals (2 coolers). Give it another shot!<br />', $total_quantity),'error' );
                            remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
                        }
                        $i++;
                    }
    
                }
    
                //Adjust snacks to match the meal quantities
                
                if ((($total_quantity == 8 ) || ($total_quantity == 20 ) ) && ($total_squantity > 4)){
                    remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
                    wc_print_notice( sprintf( 'Uh oh, looks like you added too much awesomeness. Your bag can hold only 4 snack items...<br />', $total_squantity),'error' );
                } else
                if ((($total_quantity == 9 ) || ($total_quantity == 21 ) ) && ($total_squantity > 3)){
                    remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
                    wc_print_notice( sprintf( 'Uh oh, looks like you added too much awesomeness. Your bag can hold only 3 snack items...<br />', $total_squantity),'error' );
                } else
                if ((($total_quantity == 10 ) || ($total_quantity == 22 ) ) && ($total_squantity > 2)){
                    remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
                    wc_print_notice( sprintf( 'Uh oh, looks like you added too much awesomeness. Your bag can hold only 2 snack items...<br />', $total_squantity),'error' );
                } else
                if ((($total_quantity == 11 ) || ($total_quantity == 23 ) ) && ($total_squantity > 1)){
                    remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
                    wc_print_notice( sprintf( 'Uh oh, looks like you added too much awesomeness. Your bag can hold only 1 snack item...<br />', $total_squantity),'error' );
                } else
                if ((($total_quantity == 12 ) || ($total_quantity == 24 ) ) && ($total_squantity > 0)){
                    remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
                    wc_print_notice( sprintf( 'Uh oh, looks like you added too much awesomeness. Your bag(s) do not have enough space for snacks...<br />', $total_squantity),'error' );
                }
            }
        }

    Cheers

    • This reply was modified 8 years, 5 months ago by Pradeep.
    Plugin Contributor Mike Jolley

    (@mikejolley)

    I’m on vacation so cannot check the code, but you should be adding notices not printing them.

    Hi Mike,

    Thanks for the feedback. Changed from Print Notice to Add Notice but it didn’t make any difference (apart from the correct use of displaying notices of course). I’ll wait until you come back from holidays. Have a good one!

    Hi @mikejolley,

    Could you kindly look into this next time you can spare some time for me?

    Many thanks in advance…

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Disable ajax Cart Update’ is closed to new replies.