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.

Tagged: 

This topic contains 23 replies, has 2 voices.

Last updated by Dražen Duvnjak 10 months ago.

Assisted by: Dražen Duvnjak.

Author Posts
January 19, 2024 at 2:39 pm #15205343

nikolaosM

Hello,

We are trying to make a custom export of variable products + variations and, we came up with the error below.

[19-Jan-2024 14:30:08 UTC] PHP Fatal error: Uncaught Error: Call to undefined method WP_Post::get_id() in /home/www/twomon/twomonkeys.gr/www/wp-content/plugins/woocommerce-multilingual/inc/class-wcml-wc-strings.php:103
Stack trace:
#0 [internal function]: WCML_WC_Strings->translated_attribute_label('\xCE\x97\xCE\xBB\xCE\xB9\xCE\xBA\xCE\xAF\xCE\xB1', 'pa_ilikia', Object(WC_Product_Variation))
#1 /home/www/twomon/twomonkeys.gr/www/wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Fns.php(371): call_user_func_array(Array, Array)
#2 /home/www/twomon/twomonkeys.gr/www/wp-includes/class-wp-hook.php(310): WPML\FP\Fns::WPML\FP\{closure}('\xCE\x97\xCE\xBB\xCE\xB9\xCE\xBA\xCE\xAF\xCE\xB1', 'pa_ilikia', Object(WC_Product_Variation))
#3 /home/www/twomon/twomonkeys.gr/www/wp-includes/plugin.php(205): WP_Hook->apply_filters('\xCE\x97\xCE\xBB\xCE\xB9\xCE\xBA\xCE\xAF\xCE\xB1', Array)
#4 /home/www/twomon/twomonkeys.gr/www/wp-content/plugins/woocommerce/includes/wc-attribute-functions.php(211): apply_filters('woocommerce_att...', '\xCE\x97\xCE\xBB\xCE\xB in /home/www/twomon/twomonkeys.gr/www/wp-content/plugins/woocommerce-multilingual/inc/class-wcml-wc-strings.php on line 103

The code we are using to get the variations as product objects is as below:

$variationsIDs = $newProduct->get_children(); //returns array with variations ids
foreach($variationsIDs as $variationID){
$variation = wc_get_product($variationID); //returns variation as product object
}

How can we solve it?

January 22, 2024 at 8:13 am #15209702

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

1) I would advise updating to the latest WPML versions and making a backup. Please update all WPML plugins to the latest version by going to the Plugins → Add New page, click the Commercial tab, and then click Check for updates.

- https://wpml.org/faq/install-wpml/#wpml-4-2-8

2) As for the error, it seems to be caused by your custom code. Please note we can not support or debug custom coding issues, as it would require checking all other parts of the code not only the one you shared, which is out of our scope. For custom coding service you can check WPML contractors:

- https://wpml.org/contractors/

3) In your case, what I suggest is getting the default product variation ID and then using the WPML object hook, to get the translated variation ID

- https://wpml.org/wpml-hook/wpml_object_id/

4) As for export I suggest using WP ALL Export:

- https://wpml.org/documentation/plugins-compatibility/export-multilingual-websites-using-wp-all-export-wpml/

Regards,
Drazen

January 22, 2024 at 12:56 pm #15211407

nikolaosM

Hello again,

At first the update didn't solve the problem.

About the third answer you gave, we have to say that we are only querying the default language products (Greek) so we don't export their translation. So in the lines of our custom code that we have shared in the foreach loop we get only the default variation ID. We can understand that you can not provide support for custom coding problems, but the function we are using to get the variation based on its ID is a woocommerce function that is working properly for simple and variable products. Only in product variations we get this problem.

We don't want to do the export with a plugin, because we want to export the product attributes and the free versions of export plugins do not provide that or if any of them provides it they only export simple products. That is why we came up with a custom code solution to export products in a csv file using simple PHP and woocommerce integrated functions. As you can see, we are not in need of any plugin.

Thanks!

January 22, 2024 at 1:16 pm #15211520

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

thanks for getting back.

I created a minimal installation of WordPress, WPML, and all necessary WPML add-ons.

You can access the WordPress dashboard using the link below:
- hidden link

Kindly follow the steps below:
- Try to replicate the issue with a very simple code and example
- That way we can check if this is something related to WPML plugins or an issue with custom code.

Please try to not install any additional plugins or create a fully working website, 1 product and simple code would be enough to confirm if the issue happens.

Let me know when done so I can check.

Regards,
Drazen

January 22, 2024 at 4:27 pm #15212820

nikolaosM

We have added the content in the demo site as it is in our e-shop. We can not add custom coding because we need access to public_html folder.

The way we are trying to export the products is by creating a file export-products.php in the public_html folder and we run it in the frontend. Please provide us with access to this filder or add this lines to a file in public_html flder.

require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php'); //to be able to use woocommerce functions

//get only greek published products
global $sitepress;
$sitepress->switch_lang('el');

$products = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'suppress_filters' => false
));

foreach($products as $product){
$newProduct = wc_get_product($product->ID);

if($newProduct->get_type() == 'variable'){
$variationsIDs = $newProduct->get_children();

foreach($variationsIDs as $variationID){
$variation = new WC_Product_Variation($variationID); //this is were the problem
occurs so the var_dump is not showing anything
var_dump($variation);
}
}
}

The above code is supposed to return each variation as a product object.

Thanks!

January 22, 2024 at 4:43 pm #15212915

nikolaosM

Also we think that the problem is comming from this WCML_WC_Strings->translated_attribute_label('\xCE\x97\xCE\xBB\xCE\xB9\xCE\xBA\xCE\xAF\xCE\xB1', 'pa_ilikia', Object(WC_Product_Variation)). The sting insite the first quotes is decoded as "Ηλικία" witch is the Greek word for "Age" and we use it as the attribute name / label. Can you explain what this error means?

January 23, 2024 at 7:34 am #15214244

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

as I already explained we can not debug such an issue as we need a full minimal environment, also whatever you have done has caused issues with the website and it is down.

If you have a staging site, please share wp-admin and FTP and let me have a look there. I can not guarantee anything, but we will take a look.

Let me know.

Thanks,
Drazen

January 23, 2024 at 8:49 am #15214707

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

I am sorry but I can not check / debug on live website, not much I can do nor is it safe to check such issue on live website.

Let's try again, but please do not add any additional theme or content. Just set up WPML WooCommerce and add a few dummy products manually, then using the file manager plugin add your code and test if the issue happens.

We need to check and confirm issue happens in such a minimal environment without any additional plugins, etc. As said we need to confirm this is a WPML bug issue and not a custom code issue/plugin, as we can not support or debug custom coding issues. (https://wpml.org/purchase/support-policy/)

Login link: hidden link

Thanks,
Drazen

January 23, 2024 at 1:20 pm #15216902

nikolaosM

Well, we deactivated WPML Multilingual CMS and the export worked just fine. We used the code below to export the variations.

$products = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
));

foreach($products as $product){
$newProduct = wc_get_product($product->ID);

if($newProduct->get_type() == 'variable'){
$variationsIDs = $newProduct->get_children();

foreach($variationsIDs as $variationID){
$variation = new WC_Product_Variation($variationID);
var_dump($variation);
}
}
}

So it is not a problem with the custom code. The problem is caused because of your plugin. We want to know why the plugin is not allowing product variations to be exported manually with code. Also as we asked before what is the meaning of this error

WCML_WC_Strings->translated_attribute_label('\xCE\x97\xCE\xBB\xCE\xB9\xCE\xBA\xCE\xAF\xCE\xB1', 'pa_ilikia', Object(WC_Product_Variation)).

January 23, 2024 at 1:25 pm #15216959

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

I understand, but I am not sure how should we help out if there is no way for us to check the issue and see what goes wrong and how. Also I can not know if any other part of your website is causing issue with our plugins.

The only thing that I can see is that part of of error is saying that somewhere method is being called that doesn't exist (PHP Fatal error: Uncaught Error: Call to undefined method WP_Post::get_id), as I can see from information online there is no such method, for example:

- https://wordpress.org/support/topic/fatal-error-related-to-wp_post-i-think-i-solved-it/

If you can help and reproduce the issue on shared test site, I can check further and consult with our 2nd tiers on this.

Thanks,
Drazen

January 25, 2024 at 8:42 am #15224858

nikolaosM

We will try to create a demo site. We will need some time to do this since it is a verry big site.

January 25, 2024 at 9:22 am #15225070

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

sure, take your time and let me know when done.

Regards,
Drazen

January 30, 2024 at 10:30 am #15242648

nikolaosM

Hello again,

the demo site is ready. Can you activate a private answer to send you the credentials?

Thanks!

January 30, 2024 at 10:37 am #15242673

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

sure, please also share step by step guide to check the issue.

Regards,
Drazen

January 30, 2024 at 1:44 pm #15244123

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

you are using a lot of custom code and additional plugins, as I have said we need to confirm this in a simple dummy example. We can not debug your environment and custom code, that is not in our support policy.

Please either reproduce the issue on the test site I provided before with a simple example code and 1 product or please disable all other plugins, leave active only WPML and WooCommerce ( I did this already) and use WP default theme.

Simplify the code example so it shows an issue with 1 product example, we can not debug your whole code script and environment.

Otherwise, I am afraid we can not help much and debug your custom-coded solution.

Policy: https://wpml.org/purchase/support-policy/

Or hire WPML contractors for custom code issues:

- https://wpml.org/contractors/

Regards,
Drazen