Support » Plugin: WooCommerce Advanced Free Shipping » WPML Translated categories not used for rules

  • Hi,

    I have set up some rules in my multilingual webshop (WooCommerce + WPML). These rules are set up in NL, and are set to exclude certain categories (Category not equal to xxxx). These conditions work when checking out in NL, but when someone checks out in FR, these conditions are ignored, as the product has the translated category, and passes for all conditions, so free shipping is available.

    Is this normal behavior? I will make a workaround on my own, but this should be integrated in the plugin.

    Kind regards,
    Tom

Viewing 6 replies - 1 through 6 (of 6 total)
  • The plugin checks for the category name in only one language. I have removed the wafs_match_condition_category filter, and added a custom filter that uses the category id instead of the category name.

    public function custom_wafs_match_condition_category( $match, $operator, $value ) {
            
            if ( ! isset( WC()->cart ) ) return $match;
    
            $match = true;
            
            $term = get_term_by( 'slug', $value, 'product_cat' );
    
            if ( '==' == $operator ) :
    
                foreach ( WC()->cart->cart_contents as $product ) :
    
                    if ( ! has_term( $term->term_id, 'product_cat', $product['product_id'] ) ) :
                        $match = false;
                    endif;
    
                endforeach;
    
            elseif ( '!=' == $operator ) :
    
                foreach ( WC()->cart->cart_contents as $product ) :
    
                    if ( has_term( $term->term_id, 'product_cat', $product['product_id'] ) ) :
                        $match = false;
                    endif;
    
                endforeach;
    
            endif;
    
            return $match;
    
        }

    Maybe this can be implemented in a future version?

    Plugin Author Jeroen Sormani

    (@sormano)

    Hi,

    Is that fixing things for you? I wouldn’t expect so as this change is still based on the same category that is selected at the condition, but I could be wrong..

    The plugin doesn’t have very specific features for WPML, so even though it is not particularly ‘expected behaviour’, its not exactly a bug either 😉

    Happy to include a fix if its confirmed to work by multiple people / if I can also confirm it.

    Cheers,
    Jeroen

    Hi,

    My fix does the trick for me. I was planning on writing a more complex function (first fetching all languages, then fetching the post in all languages and then check if these posts have a term that matches $value. During testing I found out simply changing the slug to the post id did the trick.

    It is quite easy to reproduce the ‘problem’.

    Kind regards,
    Tom

    Plugin Author Jeroen Sormani

    (@sormano)

    Hi,

    Would you mind writing down the steps to how to reproduce this?
    I can think of some ways myself, but I think its best to ensure I know exactly how rather then wasting time doing it the wrong way / not the same.

    Thanks,
    Jeroen

    Hi,

    After writing these steps below, I realised it’s not that easy to reproduce 🙂

    1) Install WC, WAFS, WPML, WC Multilingual
    2) Create at least 2 languages in WPML for example EN & FR, create a languageswitcher in your menu or widget for easy access
    3) Add a product ‘myproduct’, and create a category for it ‘mycagetory’
    4) Translate both the product ‘monproduit’ and the category ‘moncategory’ using WC Multilingual
    5) Add an advanced free shipping method in English
    6) Add at least 1 condition based on ‘category’. I chose ‘not equal to’, but the problem should be there when you choose ‘equal to’. Then choose the ‘mycategory’
    7) Save and test:
    – Add myproduct to your cart
    – If you visit your cart in your default language, free shipping won’t be available
    – If you change the language to the other language, free shipping will be available
    8) Apply my fix, free shipping won’t be available in both languages

    Plugin Author Jeroen Sormani

    (@sormano)

    Hi Tom,

    Sorry for the late reply, I believed I already posted one, but apparently not!

    I tried to replicate this, but I’m getting very mixed results with WPML, there’s a lot of parts that can be different for people; translated products, categories, AFS rates.
    I’m not getting any different results when changing the condition to be based on the ID vs slug, not sure why.

    I’m not apposed to the change, but I do want to ensure it does some good as this is within code that runs on many other plugins too.

    Let me know if you have any thoughts!
    Jeroen

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.