Skip Navigation

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

Problem:
If you're experiencing an issue where creating lotteries from the Dokan frontend results in the product being created as a "Simple product" instead of a "Lottery" product type when WooCommerce Multilingual & Multicurrency is enabled, it might be due to a compatibility or conflict issue.

Solution:
First, check for any errors or warnings related to WPML in the WordPress Debug log or Server Error Log. To enable WP debug log, edit your

wp-config.php

file:

define('WP_DEBUG', true);<br />define('WP_DEBUG_LOG', true);<br />define('WP_DEBUG_DISPLAY', false);<br />@ini_set('display_errors',0);

Then, replicate the issue with WCML enabled and test creating products both with and without using Dokan to determine if the issue is with Lottery, Dokan, or both.

We have found a workaround involving the cache and product lookup tables. When inserting a new product, the default product type is 'simple' due to the cache. Purging the cache group 'products' changes the product type to 'lottery'. Here's a proof of concept fix to add to your theme's functions.php:

add_action( 'wp_insert_post', 'purge_product_cache', 9, 1 );<br /><br />function purge_product_cache( $product ) {<br />    if ( get_post_type( $product ) == "product" ) {<br />        wp_cache_flush_group( 'products' );<br />    }<br />}

Please try this solution and let us know if it resolves the issue.

If this solution doesn't look relevant, please open a new support ticket.

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 14 replies, has 2 voices.

Last updated by Ilyes 1 year, 8 months ago.

Assisted by: Ilyes.

Author Posts
October 31, 2023 at 10:27 am #14698381

Никита Мороз

We have a plugin that adds the “Lottery” product type, and we use the “Dokan” plugin to allow users to post products from the frontend. The Lottery plugin (developed by wpgenie) also has a Dokan and Lottery integration module.

What is the main problem:

When creating lotteries from the Dokan frontend, for some reason the product is created as a “Simple product”. This issue only occurs if WooCommerce Multilingual & Multicurrency is enabled.

Question: what could be the problem? Can WPML Woocommerce somehow change the product type when saving? Why does the product type change from Lotrey to Simple when the product translation plugin is enabled? Have you encountered this?

Clarification - we also have an auction plugin from the same developers and this is not a problem, auction products are created from the Dokan frontend without such errors, although this is also a custom product type.

You may request access to the site, but our site is closed to IP addresses other than the white list.

October 31, 2023 at 4:44 pm #14702551

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

Thank you for contacting WPML support team,

After checking our compatibility list : https://wpml.org/plugin/ , I wasn't able to locate wpgenie's plugins there,

This could indicate a compatibility/conflict issue between WCML (Woocommerce Multilangual) and WooCommerce Lottery.

Dokan is indeed listed as compatible but that doesn't mean we shouldn't test it further,

It seems you have a very specific environment set up in order to get to this kind of issue, to eliminate multiple scenarios, I'm not sure how these two plugins are working together, but it would really help to do the following tests before getting to the next step of debugging :

Please check if you are getting any errors or warnings related to WPML in the WordPress Debug log or Server Error Log while having this issue. May you need your hosting team's support to access the server error log file.

To enable WP debug log, open your wp-config.php file and look for:

define('WP_DEBUG', false);

And change it to:

define('WP_DEBUG', true);

// Enable Debug logging to the /wp-content/debug.log file

define('WP_DEBUG_LOG', true);

// Disable display of errors and warnings which is recommended on a live site.

define('WP_DEBUG_DISPLAY', false);

@ini_set('display_errors',0);

Then try replicating the issue in 2 different scenarios :

1- Keep WCML enabled
2- Are you able to create the same product without using Dokan? if so, test it and see if the issue persists
3- Are you able to create another product (that is not from Lottery plugin) using Dokan?

The idea is to see if the issue is either coming from Lottery, Dokan or Both. At the same time logging any potential obvious errors.

Please let me know your findings,

Best,

October 31, 2023 at 6:21 pm #14703177

Никита Мороз

We did some tests. We used a different site, a different set of plugins and a standard theme - the problem was always with the dokan - lottery - WCML set.

Again, the strangest thing is that auctions from the same developers work properly.

This is what part of the code for the form for sending a lottery product from Dokan looks like:

<div class="dokan-form-group">
<input type="hidden" name="product-type" value="auction">
<?php wp_nonce_field( 'dokan_add_new_auction_product', 'dokan_add_new_auction_product_nonce' ); ?>
<input type="submit" name="add_auction_product" class="dokan-btn dokan-btn-theme dokan-btn-lg dokan-right" value="<?php esc_attr_e( 'Add auction Product', 'dokan' ); ?>"/</div>

For auctions it is almost identical. But there is no problem with auctions.

We've added logging to the code that accepts POST on the server side. Logging shows that the form sends [product-type] => lottery

But at the same time some changes occur and the product becomes => simple

I basically don’t understand how WCML can intercept the result and change it, but the fact remains that when this plugin is turned off, lotteries are saved properly.

We contacted the support of the lottery plugin, unfortunately they couldn’t help us and advised us to contact you...

October 31, 2023 at 6:22 pm #14703179

Никита Мороз

And yes, we can create other types of goods from Dokan - variable, auction, affiliate. This is all being created.

We can also create lottery products without Dokan from the WordPress admin panel - this is also not a problem.

October 31, 2023 at 6:40 pm #14703295

Никита Мороз

An example of logging - the first two records are what the server receives from the lottery product creation form.

The last record is the final product type - logging occurs immediately after the product is created. As you can see from the logs, literally after 5 seconds the product type is already simple. This problem disappears if WCML is disabled.

[31-Oct-2023 18:32:57 UTC] Received POST data: Array
(
[feat_image_id] => 0
[product_image_gallery] =>
[post_title] => Тест лотереи (WCML)
[post_excerpt] => 123
[chosen_product_cat] => Array
(
[0] => 35
)

[_lottery_price] => 90
[_lottery_sale_price] => 9
[_min_tickets] => 10
[_max_tickets] => 20
[_max_tickets_per_user] => 1
[_lottery_num_winners] => 1
[_lottery_dates_from] => 2023-10-31 20:32
[_lottery_dates_to] => 2023-11-30 00:00
[product_type] => lottery
[_lottery_pick_number_tab_qty] =>
[_lottery_question] =>
[post_content] =>
[product-type] => lottery
[dokan_add_new_lottery_product_nonce] => 4f02c5489c
[_wp_http_referer] => /my-store-control/new-lottery-product/
[add_lottery_product] => Додати лотерейний товар
)

[31-Oct-2023 18:32:57 UTC] Product created with ID: 13504 and type: product
[31-Oct-2023 18:33:02 UTC] Product ID: 13504 has type: simple

November 1, 2023 at 4:46 pm #14709269

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

Thank you for the thorough testing in different scenarios and environment,

This is a case that requires further testing by our compatibility team, this is why in order to see if this issue is happening because of the configuration of your staging site, or just the combination of Dokan, Lottery & WPML we need to isolate the issue.

I’ve created a sandbox here: hidden link

I’ve already configured WPML in 2 languages (en / ru), and added All plugins except of Dokan and Lottery.

Please do the following:

- Open the Sandbox link mentioned above.
- Leave WPML plugins active.
- Download and activate Dokan and Lottery plugins.
- Create a page where you can add a lottery through Dokan's interface.
- Create a Lottery product type.
-> Does the issue replicate? Was the product type changed to Simple product?

If so, please send us the link where we can create a lottery product and track why it got changed.

Please note that we only need the theme/plugin and the related functionality, you don’t need to setup a entire website or clone your existing site.
https://wpml.org/faq/how-to-reproduce-issues-and-share-them-with-wpml-support/

Thank you so much for your collaboration and please let me know when it is done.

Best regards,

November 2, 2023 at 12:41 pm #14716741

Никита Мороз

It's strange, but everything works in your sandbox.

On our second site, we repeated the set of plugins, themes, plugin versions are the same as you have in the sandbox. The only thing missing is the Multilangual Tools plugin. But with an identical set to your sandbox, our lottery products still become “Simple”.

November 2, 2023 at 5:45 pm #14720319

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

That is strange indeed, at least we made sure that this is related to your specific website,

Here is how we could help in this case, I could escalate this to our 2nd tier team to do their own tests, I would like to ask for temporary access to your test site’s wp-admin and FTP to investigate the issue further.

Kindly provide me with a detailed list of steps on how to replicate the problem.

If necessary, I may need to replicate your site locally. To do this, I will temporarily install a plugin called “Duplicator” on your site, which will enable me to create a copy of your site and its content. Once the problem has been resolved, I will delete the local site. Please let me know if you agree to this.

It is important to note that you should back up your site and database before proceeding, and you can use a plugin like Duplicator for this purpose. Here’s a link to the plugin: http://wordpress.org/plugins/duplicator/

If you do not see the form below, please do not enter your credentials as they will be publicly exposed:

hidden link

For your privacy and security, please ensure that you make your reply a private one.

Best regards,

November 2, 2023 at 7:07 pm #14720645

Никита Мороз

As I mentioned earlier, our site is closed to other IP addresses, except those on the white list. Can I create a duplicate of the site myself and send it to you?

November 2, 2023 at 7:32 pm #14720763

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello again,

Yes, getting a copy instead of the main site is possible as long as the issue is replicating on the duplicate,

It is also worth replicating it under your local machine just in case, to test if the issue is server related,

In all cases, I'm likely to download a copy of your site if that's okay, or better, you can directly send us a copy if available below,

I have opened the necessary private field below to share your site and credentials securely,

Best,

November 6, 2023 at 8:48 pm #14741971

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

The site duplicator copy is working locally, thank you,

Just to make sure we are getting the same issue, I have created this lottery product : hidden link

And then when I go to your products list, I find it listed as a simple product : hidden link

I confirm that this is happening solely because of your specific site, I'm escalating this to our 2nd tier team, hoping they could find a quick fix for this,

Thank you for your patience,

November 7, 2023 at 5:35 pm #14750799

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

Unfortunately, this might take more time than expected, I had to escalate to our 2nd tier team as I wasn't able to detect any errors or differences between installations (Sandbox and your copy)

I will get back to you once I receive an update,

Best,

November 8, 2023 at 4:58 pm #14759553

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

Thanks for your patience,

We have been able to find a workaround that fixed the issue on our copy, please watch this video showing what is needed to be done : hidden link

The problem appears to be cache and product lookup tables.
Upon you do an insert of a new product, it tries to obtain the product type and by default it is simple in the cache group "plugins".
If you purge that cache group - then it is "lottery"

Here is a proof of concept fix that you can place in your themes functions.php:

add_action( 'wp_insert_post', 'purge_product_cache', 9, 1 );

function purge_product_cache( $product ) {
	if ( get_post_type( $product ) == "product" ) {
		wp_cache_flush_group( 'products' );
	}
}

Please let us know if it worked for you,

November 9, 2023 at 1:31 pm #14767407

Никита Мороз

Thank you very much, the code works! I would like to know if this code that you provided could somehow potentially affect other elements of the site? Will this become a problem elsewhere?

November 9, 2023 at 4:12 pm #14769923

Ilyes
Supporter

Languages: English (English ) French (Français ) Arabic (العربية )

Timezone: Pacific/Easter (GMT-06:00)

Hello,

I'm glad it worked,

Rest assured, this code will only force a purge for that specific cache group, it should not interfere with other elements of your site,

Best,