Skip Navigation

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.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 14:00 12:00 – 14:00 12:00 – 14:00 12:00 – 14:00 12:00 – 14:00 -
- 17:00 – 21:00 17:00 – 21:00 17:00 – 21:00 17:00 – 21:00 17:00 – 21:00 -

Supporter timezone: Europe/Vienna (GMT+01:00)

This topic contains 15 replies, has 3 voices.

Last updated by Sumit 1 year, 7 months ago.

Assisted by: Bigul.

Author Posts
July 18, 2022 at 11:00 am #11685005

desireeM

I don't want to use the WPML custom prices, but use my own custom prices.

Unfortunately, you loaded it with the object:
`add_filter( 'init', [ $this, 'custom_prices_init' ] );`

Unfortunately, it's impossible to remove_filter for this without either bad performance (re-init the class in global context and remove filter with new instance) or without hacking WP core actions/filters global.

Can you please make the class instance available as a global so it's easy to remove_filter (or make the class static)

July 18, 2022 at 3:09 pm #11686887

Bigul
Supporter

Languages: English (English )

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

Hello,

Welcome to the WPML support forum. I will do my best to help you to resolve the issue. A couple of requests for tracking this.

a) Please let us know the exact steps to reproduce the issue on your site. Because most probably it needs escalation to our developers.

b) To help you faster, I've enabled debug information for this support ticket. Please see this link for how to get this information from your site and give it to us: http://wpml.org/faq/provide-debug-information-faster-support/

--
Thanks!

Bigul

July 21, 2022 at 7:28 am #11707033

desireeM

Hi,

a) try to remove_filter the `custom_prices_init` from e.g. a theme's functions.php, which should then not load those custom prices in product edit page.

b) This is a pure code issue with your code base, ie that remove_filter to remove WCML custom prices is currently not possible, without modifying the global filter object, which is a really bad practice. This has nothing to do with my install.

Please forward it to your developers, so they can take a look at it and fix it.

July 21, 2022 at 4:01 pm #11712497

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the updates. I have consulted about this with our developers. We have a couple of doubts.

a) Is there any specific reasons to remove the custom filter price? Because normally we can simply avoid using custom prices.

b) Even if removing this filter, it is possible that WooCommerce Multilingual may not work properly with some warnings or errors. So is it okay for you to reproduce the issue in our sandbox site(a fresh installation)? Because it will help us a lot in debugging.

Please let us know your feedback. We will do our best to resolve this as soon as possible.

--
Thanks!

Bigul

July 21, 2022 at 7:26 pm #11713935

desireeM

Dear Bigul,

a) yes, I want to user other custom prices and not load the WCML custom prices at all for performance and usability reasons.

b) as I told you in the beginning, right now remove_filter is NOT possible without instantiating it as a class in global context. How do you reproduce something that currently is not possible?
I want to `remove_filter` the filter you add as `add_filter( 'init', [ $this, 'custom_prices_init' ] );`

I also outlined the solution in the first post.

July 22, 2022 at 3:32 pm #11720857

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the feedback. I have shared the details with our team and waiting for the updates now. We will get back to you as early as possible. Please wait.

--
Thanks!

Bigul

July 27, 2022 at 8:24 am #11748183

Bigul
Supporter

Languages: English (English )

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

Hello,

Our developers have a doubt about this. Please read the following and let us know your feedback.


These hooks are active only if we set up multicurrency from WooCommece Multilingual, so why remove them if you are using something else for multicurrency?

--
Thanks!

Bigul

July 27, 2022 at 9:36 am #11749019

desireeM

Because I use multi-currency of WCML plugin - I just use a different (much improved) interface in wp-admin on the product edit pages, that allows for more custom control on per domain and currency level.
That's why I want to remove_filter this on the edit page, as I don't need it there.

July 28, 2022 at 2:02 pm #11760071

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the updates. We would like to know which third-party plugins you are using for the following functionalities. Because there are chances for compatibility issues also.


I just use a different (much improved) interface in wp-admin on the product edit pages, that allows for more custom control per domain and currency level

--
Thanks!

Bigul

August 4, 2022 at 8:06 am #11800355

desireeM

It's a custom development.
There are no compatibility issues.

Atm we just commented your badly coded add_filter (since the other way has severe performance penalties), but we don't want to maintain a fork and guide you towards WP and PHP best practices.

August 4, 2022 at 4:49 pm #11806541

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you for the updates. For your kind information, we are not able to reproduce the issue exactly. Therefore it will be great if we get a copy of the site for debugging.

A wild guess. We would like to know whether the following library will help in your case or not. Because it will help to remove any stubborn filters.

hidden link

--
Thanks!

Bigul

August 5, 2022 at 9:23 am #11809685

desireeM

>For your kind information, we are not able to reproduce the issue exactly.

How did you try to reproduce it?

August 5, 2022 at 4:30 pm #11812061

Bigul
Supporter

Languages: English (English )

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

Hello,

To be honest we only have a rough idea about this bug and we are stuck on this. Our developers have tried some testing as per your feedback.

Therefore it will be great if you can share a test copy with the exact steps to reproduce. It will really speed up the process. Thank you for your understanding.

--
Thanks!

Bigul

August 9, 2022 at 5:26 am #11828747

desireeM

The goal/problem is to remove_filter for this code in WCML:
`add_filter( 'init', [ $this, 'custom_prices_init' ] );`

Reproduce:
Use any standard WPML + WCML install.
Put this code anywhere in theme (e.g. functions.php):

```
// obviously won't work, since custom_prices_init is not a static method
remove_filter( 'init', array( 'WCML_Custom_Prices', 'custom_prices_init' ) );

// try it with instantiating the class (which wastes performance), but won't work either
function remove_it_please() {
global $woocommerce_wpml, $wpdb;
$instance = new WCML_Custom_Prices( $woocommerce_wpml, $wpdb);
remove_filter( 'init', array( $instance , 'custom_prices_init' ) );
}
// runs earlier
add_action( 'plugins_loaded', 'remove_it_please', 10, 0 );
// same hook, but early
add_action( 'init', 'remove_it_please', 5, 0 );
```

There is a complex workaround by modifing the global WP hooks object, however this is an extremely bad practice and really bad for performance.

Best practices are (you can do either):
- make custom_prices_init a static method and add_filter with `'WCML_Custom_Prices::custom_prices_init'` or `[ 'WCML_Custom_Prices', 'custom_prices_init' ]`
or
- use singleton pattern https://wordpress.stackexchange.com/questions/36013/remove-action-or-remove-filter-with-external-classes#:~:text=One%20thing%20I%27ve,the%20original%20plugin

August 9, 2022 at 4:23 pm #11834169

Bigul
Supporter

Languages: English (English )

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

Hello,

Thank you very much for the details. The ticket is escalated to our second-tier team for further debugging and testing. We will get back to you as early as possible. Please wait.

--
Thanks!

Bigul

The topic ‘[Closed] remove_filter for custom_prices_init’ is closed to new replies.