Closed futyko closed 2 years ago
Hi @futyko We have had reports of this being caused by the Flatsome screen edit product UI, where the other product in question is introduced by one of the Flatsome theme shortcodes. Could you test with a default theme and confirm?
Hi @nicdwilson
Thank yo so much for your prompt reply and sorry for my negligence, as I haven't tried to change the theme. Yes, I can confirm this bug goes away by using 2020 default theme.
However I am not sure what you meant by 'where the other product in question is introduced by one of the Flatsome theme shortcodes'.
Do you happen to know a workaround or a solution?
Thank you and have a nice day!
Closing
this being caused by the Flatsome screen edit product UI, where the other product in question is introduced by one of the Flatsome theme shortcodes. Could you test with a default theme and confirm?
@futyko @nicdwilson @jconroy
It's due to a long time WP Core bug
Shortcodes in Flatsome use WP_Query
to query f.ex. products and set the global in the loop with ->the_post()
, and this function https://github.com/woocommerce/facebook-for-woocommerce/blob/master/includes/fbutils.php#L167-L168
executes shortcodes in the admin area (on the description, excerpt, title), making the global post not to be reset.
That essentially means that any shortcode that uses a query and set the global post with the loop in their shortcode will have this issue, not only Flatsome. As wp_reset_query
or wp_reset_postdata
does not work as expected in the admin.
It seems the only way to circumvent this would be to:
In code:
global $post;
$old_post = $post; // Store $post for restoration
// Do stuff
$post = $old_post; // Restore the global $post
or
$original_post = $GLOBALS['post'];
// Do stuff
$GLOBALS['post'] = $original_post;
@JimmyAppelt Thank you so much for the details!
@nicdwilson @jconroy Would you please review the ticket based on Jim's comment? Thank you!
"The way I was able to replicate the issue is to add a products shortcode in the product description.
FfW will execute the shortcode in the backend (admin) when editing the product, which is the issue in itself as the last product in the loop of that shortcode on there is going to be set as post data (because of the WP bug that the original post is not been reset in the admin by doing that)
The best way to fix this is FfW having reset the original post after it has executed the shortcodes.
FfW will have the same problem with any theme or plugin shortcode like so, if not fixed on their side."
We've also disabled the sync as per the other threads. It is still misbehaving.
@rawdreeg You're welcome đ
Thanks @JimmyAppelt for the detailed explanation đ Helped a ton đ
Thanks @JimmyAppelt for the detailed explanation đ Helped a ton đ
@rawdreeg thank you for applying a workaround in the plugin core đ
đ Isolate the bug
âïž Describe the bug
It seems to be the same issue, as described in " slug bug on product update #2127 ".
When I click on editing a product, the /wp-admin/post.php?post=21&action=edit loads the product details with values from a different product. The long description is the same, but the short description is completely coming from an other product. The product slug also changes to the slug of another product. The price and stock values also changing to represent the other product.
The other product is always postid=565 for category A. Except if I am trying to update a product from category B, it is feeding the info from product id 1023 for all the products in this cat.
Your kind response is greatly appreciated! Thank you in advance!
đ¶ââïž Steps to reproduce
The above mentioned issue only occurs if product sync is turned on.
âïž Expected behavior
Working w/o this bug, I am pretty sure :)
đ Logs