Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
I am trying to restrict the payment methods for a purchase in a WC shop, in the second languages. But the tab "Payments" is not available in a WC product in the second languages with WooCommerce Payment Gateway per Product.

Solution:
- Open your file /wp-content/plugins/woocommerce-product-payments/include/payment.php
- Look for the line 114.
- Add the following:

$item['product_id'] = apply_filters( 'wpml_object_id', $item['product_id'], 'product', true, apply_filters( 'wpml_default_language', NULL ) );

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.

Our next available supporter will start replying to tickets in about 2.26 hours from now. Thank you for your understanding.

This topic contains 23 replies, has 2 voices.

Last updated by Andrés 9 months, 3 weeks ago.

Assigned support staff: Andrés.

Author Posts
October 21, 2019 at 5:55 am #4791215

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Thank you for the contact details you provided, Stefan. I will forward the details to our Themes & Plugins Compatibility Team and they will contact the author.

Please note that this process may take a while as it depends on how soon the author will reply to our efforts to contact him.

It would be great if you can also contact the author asking him to reply us. You could also refer them to our Go Global program so that we can help them make their product compatible with WPML.

Regards,
Andrés

October 21, 2019 at 2:43 pm #4795311

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Hello Stefan,

I just received a first feedback:

- Make a full backup of your site.
- Open your file /wp-content/plugins/woocommerce-product-payments/include/payment.php
- Look for the lin 114.
- Add the following:

$item['product_id'] = apply_filters( 'wpml_object_id', $item['product_id'], 'product', true, apply_filters( 'wpml_default_language', NULL ) );

- Save your file.
Now, it should apply the same methods than your original product.

Does it work now?

October 21, 2019 at 3:57 pm #4796045

stefanA-12

Hello Andrés,

sounds good to have a solution! 🙂

I tried to add the code, but line 114 is possible not the exactly position to do that?

This is in line 114: foreach ( $items as $item ) {

I can´t find the way to add it in the right manner. 🙁

Can you tell me the exactly position to add the code, please?

Append a screenshot to that.

Many thanks,

Stefan

October 22, 2019 at 5:11 am #4798857

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Perfect, Stefan. That would give something like:

foreach ( $items as $item ) {
    $item['product_id'] = apply_filters( 'wpml_object_id', $item['product_id'], 'product', true, apply_filters( 'wpml_default_language', NULL ) );

Regards

October 22, 2019 at 9:51 am #4800763

stefanA-12

Hey Andrés,

then the code look like this now:

/**
* checking all cart products
*/

if ( is_object( $woocommerce->cart ) ) {
$items = $woocommerce->cart->cart_contents;
$itemsPays = '';
if ( is_array( $items ) ) {
foreach ( $items as $item ) {
$item['product_id'] = apply_filters( 'wpml_object_id', $item['product_id'], 'product', true, apply_filters( 'wpml_default_language', NULL ) );
if ( !is_product_eligible( $item['product_id'] ) ) {
continue;
}
$itemsPays = get_post_meta( $item['product_id'], 'sd_payments', true );
if ( is_array( $itemsPays ) && count( $itemsPays ) ) {
foreach ( $arrayKeys as $key ) {
if ( array_key_exists( $key, $available_gateways ) && !in_array( $available_gateways[$key]->id, $itemsPays ) ) {

if ( $default_payment == $key ) {
$is_default_pay_needed = true;
$default_payment_obj = $available_gateways[$key];
unset( $available_gateways[$key] );
} else {
unset( $available_gateways[$key] );
}

}
}
}
}
}
/**
* set default payment if there is none
*/

But this not function, it comes to the following message: The site is experiencing technical difficulties.

Append a screenshot to that.

Reg., Stefan

October 22, 2019 at 10:32 am #4801357

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

I would like to request temporary access (wp-admin and FTP) to your test site to take a better look at the issue. Could you please indicate me how to replicate this behaviour?

You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Maybe I'll need to replicate your site locally. For this, I’ll need to temporarily install a plugin called “Duplicator” on your site. This will allow me to create a copy of your site and your content. Once the problem is resolved I will delete the local site. Let me know if this is ok for you.

*Important: Be sure to backup your site and database first before you proceed!
You can use a plugin for this if you like. You can use the Duplicator plugin for this purpose.
See: http://wordpress.org/plugins/duplicator/

If you don't see the form below, pelase don't add your credentials as they will be publicly exposed:
hidden link

Privacy and Security when Providing Debug Information for Support:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

October 22, 2019 at 1:20 pm #4802815

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Thank you for your credentials, Stefan.
I've accessed to your site and apply the patch, it seems to be working now. Could you please give it a look?

October 22, 2019 at 2:41 pm #4803409

stefanA-12

My issue is resolved now. Thank you!

October 22, 2019 at 3:55 pm #4804057

Andrés
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Europe/Paris (GMT+02:00)

Super! 🙂
Have a nice day.