Please make sure to update to WPML to the latest and check our list of Known Issues before reporting

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.


This topic contains 3 replies, has 2 voices.

Last updated by Bruno Kos 6 months, 1 week ago.

Assigned support staff: Bruno Kos.

Author Posts
August 10, 2019 at 9:08 am #4375031


Tell us what you are trying to do? I use customized code in Functions.php and I want this affects in all languages, but now it works only in main language. Can I send you the code, so you can look it and suggest me some changes? I really need help with this!
Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

August 12, 2019 at 7:50 am #4378979

Bruno Kos

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)


Thank you for contacting WPML support!

I use customized code in Functions.php

Can you show us the code and tell us what it is supposed to do? Usually the custom code is outside of the scope of WPML support and we tell clients to reach out to our contractors, but perhaps we can help you:

On a side note, you may want to check this:

Bruno Kos

August 15, 2019 at 8:25 am #4399475


The code is here:

add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_shipping_class', 10, 2 );
function hide_shipping_method_based_on_shipping_class( $rates, $package )
if ( is_admin() && ! defined( 'DOING_AJAX' ) )

// HERE define your shipping class to find
$class = 2937;

// HERE define the shipping methods you want to hide
$method_key_ids = array('smartpost_estonia', 'dpd_shops_ee');

// Checking in cart items
foreach( $package['contents'] as $item ) {
// If we find the shipping class
if( $item['data']->get_shipping_class_id() == $class ){
foreach( $method_key_ids as $method_key_id ){
unset($rates[$method_key_id]); // Remove the targeted methods
break; // Stop the loop
return $rates;

This code hides two shipping methods ('smartpost_estonia', 'dpd_shops_ee') when shipping class is choosed.
Now it works only with main language. How to make it work in all languages? Maybe you have some standard code snippet to use in cases like this?

Thank you!

August 19, 2019 at 6:31 am #4413685

Bruno Kos

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hi Diana,

Examining, testing and providing fix for custom code is normally outside of what WPML support offers and does I'm afraid. This is when we send clients to consult our experienced contractors:

I'm not sure though whether you have seen this code already?

It seems like this is an exact quote as yours, but only updated. Your issue might be related to:

$classes = [3031, 3032];

Or perhaps defining IDs of translated shipping classes, and not only originals?

And as I mentioned before, you may also consider using language constants:

In other words, functions loaded only in specific languages, based on the language code.

Can you also have a look at this answer, it may explain some things as well:

All these answers given by our supporters have one thing in common:

"You can restrict shipping methods only by country, not by language, as shipping methods are going to be controlled via Woocommerce and not WPML."

Bruno Kos