Home Forums WoodMart support forum Problems with filter woocommerce_add_to_cart_fragments

Problems with filter woocommerce_add_to_cart_fragments

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #481808

    metuza
    Participant

    Hello,

    Is there anything in Woodmart that possible can disturb the filter “woocommerce_add_to_cart_fragments” ?

    I have for years used it to add a message if order is overweight etc. and just noticed that it does no longer work in my 2 webshops where i am using it.

    I have tested it now with just a simple message but it is totally dead in both my websites.

    Brgds
    Rune

    #481819

    metuza
    Participant

    Forgot to mention that i have tested with ALL plugins and extra codes disabled, but issue is the same, filter is dead.

    Brgds
    Rune

    #481888

    Artem Temos
    Keymaster

    Hi,

    Please, describe to us your problems in a bit more detail. Attach some screenshots and provide us with a list of steps on how to reproduce them on your website.

    Thank you in advance.

    #481913

    metuza
    Participant

    Hello,

    If you add to cart these 2 products:
    https://www.arctic-fritid.no/produkt/videreforedling/marinader-og-urter/seilaksfarge-10g/
    https://www.arctic-fritid.no/produkt/videreforedling/kaldroyking/roykeklosser-av-or-matroyk/

    Then you should find that the woodmart shipping progressbar dissapear and a message appear with text “Frakt tilkommer da ordren må leveres fra lokal- og sekundærlager” in english (Shipping is added as the order must be delivered from local and secondary warehouses).

    But the above does no longer happend.

    Also by empty cart again and adding 3 pcs of this product:
    https://www.arctic-fritid.no/produkt/friluftsliv/telt-og-lavvo/telt/coleman-darwin-3-telt/

    Then you should find that the woodmart shipping progressbar dissapear and a message appear with text “Frakt tilkommer da din nåværende ordre har en totalvekt på over 10 kg.” in english (Shipping is added as your current order has a total weight of more than 10 kg).

    But also this happend anymore.

    I will guess that it is everything betwwen 2-4 months since last time i tested the above and all working ok. Wierd is that it now has dissapeared on 3 of my sites.

    I have tested today with all plugins deactivated and using storefront theme but with no luck, issue is the same. It seems like the filter is not active as i can force in fatal errors in code which normally would have caused some issues with loading in cart page, but whatever i do no problems in cart.

    Message placeholder is in place and working – div.aws-free-shipping

    This is the code i have been using for 4-5 years:

    // Add shipping messages to cart page

    function afas_woocommerce_shipping_fragment( $fragments ) {
    
         $postkasse = false;
         $pakke_hentested = false;
         $unstocked = false;
         $price = false;
         $extra = false;
    
         foreach( WC()->cart->get_cart_contents() as $key => $values ):
    
    	$product = $values[ 'data' ];
    
    	if ( $values[ 'data' ]->get_shipping_class_id() == 716 ) // Pakke i postkassen
    		$postkasse = true;
    
    	if ( $values[ 'data' ]->get_shipping_class_id() == 717 ) // Pakke til hentested
    		$pakke_hentested = true;
    
    	if ( $values[ 'data' ]->get_shipping_class_id() == 715 ) { // Unstocked
    		$unstocked = true;
    	} else {
    		$quantity = $values[ 'quantity' ];
    		$item_price = wc_get_price_including_tax( $product );
    		$price += ($item_price * $quantity);
    	}
    
         endforeach;
    
            if ( $unstocked && ( $postkasse || $pakke_hentested ) ) $extra = true;
    
    	ob_start();
    
    	$cart_total = is_object( WC()->cart ) ? WC()->cart->subtotal : '';
    	$cart_total_weight = is_object( WC()->cart ) ? WC()->cart->get_cart_contents_weight() : '';
    
    	if ( $extra || ( $cart_total_weight >= 10 && $cart_total_weight < 99 && $cart_total ) ) {
    
    	afas_shipping_popup( $cart_total_weight, $extra, $price );
    
    	} else if ( $cart_total_weight >= 99 ) {
    
    	afas_shipping_popup( $cart_total_weight, $extra, $price );
    
    	} else {
    
    	afas_shipping_popup_placeholder();
    
    	}
    
    	$content = ob_get_clean();
    
    	$fragments['div.aws-free-shipping'] = $content;
    	return $fragments;
    
    }
    add_filter( 'woocommerce_add_to_cart_fragments', 'afas_woocommerce_shipping_fragment' );
    
    function afas_shipping_popup( $cart_total_weight, $extra, $price ) {
    
    	if ( $extra && $price < 1499 ) {
    	echo '<style>.wd-free-progress-bar {display:none;visibility:hidden;}</style>';
    	echo wc_print_notice( 'Frakt tilkommer da ordren må leveres fra lokal- og sekundærlager.<br/><small style="margin-left: 0;">Alle Matrøyk-produkter sendes direkte fra fabrikken på Nøtterøy.</small>', 'notice' );
    	}
    	
    	if ( $cart_total_weight >= 10 && $cart_total_weight <= 99 ) {
    	echo '<style>.wd-free-progress-bar {display:none;visibility:hidden;}</style>';
    	echo wc_print_notice( 'Frakt tilkommer da din nåværende ordre har en totalvekt på over 10 kg.', 'notice' );
    	} else if ( $cart_total_weight > 99 ) {
    	echo '<style>.wd-free-progress-bar {display:none;visibility:hidden;}</style>';
    	echo wc_print_notice( 'Vi kan dessverre ikke levere din ordre da vi har en vektbegrensning på ca. 100 kg.', 'notice' );
    	}
    
    }
    
    function afas_shipping_popup_placeholder() {
    
    	echo '<div class="aws-free-shipping"></div>';
    
    }
    add_action( 'woocommerce_before_cart_table', 'afas_shipping_popup_placeholder', 10 );

    I have also tried with priority on the filter from -1 to 999 but no luck. And also simplified the above code to not use any conditionals / values etc. just hardcoded message, but seems to be totally dead.

    Code is added to a included file in functions.php in child theme. Also tried to move it into woodmart theme functions.php

    So any idea on what could be wrong has been great 🙂

    I will activate a staging site for further testing.

    Brgds
    Rune

    #481915

    Artem Temos
    Keymaster

    Hello,

    Do you mean that the code doesn’t work with other themes as well? In this case, this issue is not related to WoodMart. It is a WooCommerce filter and if your code doesn’t work with any theme then there might be something in the WooCommerce plugin.

    Kind Regards

    #481926

    metuza
    Participant

    Yes, earlier today i tested using Storefront. Added my code directly into storefronts functions.php but with no luck.

    But isnt your shipping progress bar added and updated using the same filter? That seems to work ok.

    Anyway, will be better to test on this when i get the staging up.

    Brgds
    Rune

    #481929

    Artem Temos
    Keymaster

    Hello,

    When you switch to the Storefront theme our theme doesn’t add any functionality to the website and any files are loaded. So if the code doesn’t work with other themes then it is not something caused by WoodMart.

    Kind Regards

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