woocommerce / facebook-for-woocommerce

A first-party extension plugin built for WooCommerce. Development is managed by Ventures.
https://woocommerce.com/products/facebook/
GNU General Public License v2.0
210 stars 137 forks source link

Bug on product update prevents modifying the stock levels and price #2145

Closed futyko closed 2 years ago

futyko commented 2 years ago

🔎 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

` ### WordPress Environment ### WordPress address (URL): https://parajdisoparna.hu Site address (URL): https://parajdisoparna.hu WC Version: 6.1.0 REST API Version: ✔ 6.1.0 WC Blocks Version: ✔ 6.5.1 Action Scheduler Version: ✔ 3.4.0 WC Admin Version: ✔ 3.0.3 Log Directory Writable: ✔ WP Version: 5.8.3 WP Multisite: ✔ WP Memory Limit: 256 MB WP Debug Mode: – WP Cron: ✔ Language: hu_HU External object cache: – ### Server Environment ### Server Info: Apache PHP Version: 7.4.27 PHP Post Max Size: 8 MB PHP Time Limit: 30 PHP Max Input Vars: 1000 cURL Version: 7.71.0 OpenSSL/1.1.1d SUHOSIN Installed: – MySQL Version: 5.5.5-10.3.32-MariaDB-cll-lve Max Upload Size: 1 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔ ### Database ### WC Database Version: 5.6.0 WC Database Prefix: wp_2_ Teljes adatbĂĄzis mĂ©rete: 37.35MB AdatbĂĄzis adatok mĂ©rete: 21.36MB AdatbĂĄzis index mĂ©rete: 15.99MB wp_2_woocommerce_sessions: Data: 1.02MB + Index: 0.02MB + Engine InnoDB wp_2_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_2_woocommerce_order_items: Data: 0.44MB + Index: 0.13MB + Engine InnoDB wp_2_woocommerce_order_itemmeta: Data: 2.52MB + Index: 4.00MB + Engine InnoDB wp_2_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_2_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_2_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_2_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_actionscheduler_actions: Data: 0.09MB + Index: 0.13MB + Engine InnoDB wp_2_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_actionscheduler_logs: Data: 0.08MB + Index: 0.03MB + Engine InnoDB wp_2_adtribes_my_conversions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_aepc_custom_audiences: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_2_aepc_logs: Data: 0.39MB + Index: 0.00MB + Engine InnoDB wp_2_billingo_documents: Data: 0.11MB + Index: 0.08MB + Engine InnoDB wp_2_billingo_partnerhash: Data: 0.08MB + Index: 0.00MB + Engine InnoDB wp_2_commentmeta: Data: 0.06MB + Index: 0.06MB + Engine InnoDB wp_2_comments: Data: 1.52MB + Index: 1.08MB + Engine InnoDB wp_2_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_options: Data: 2.16MB + Index: 0.11MB + Engine InnoDB wp_2_postmeta: Data: 5.52MB + Index: 6.94MB + Engine InnoDB wp_2_posts: Data: 2.50MB + Index: 0.39MB + Engine InnoDB wp_2_rank_math_404_logs: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_rank_math_internal_links: Data: 0.14MB + Index: 0.05MB + Engine InnoDB wp_2_rank_math_internal_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_2_rank_math_redirections: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_rank_math_redirections_cache: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_social_users: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_2_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_2_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_2_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_2_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_2_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_2_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_2_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_2_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_blogmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_blogs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_registration_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_signups: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_site: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_sitemeta: Data: 1.03MB + Index: 0.03MB + Engine InnoDB wp_usermeta: Data: 2.67MB + Index: 1.61MB + Engine MyISAM wp_users: Data: 0.15MB + Index: 0.19MB + Engine MyISAM ### Post Type Counts ### attachment: 77 blocks: 40 customize_changeset: 2 nav_menu_item: 4 page: 8 post: 4 product: 41 revision: 592 shop_coupon: 1 shop_order: 1119 ### Security ### Secure connection (HTTPS): ✔ Hide errors from visitors: ✔ ### Active Plugins (20) ### Klasszikus szerkesztƑ: Ă­rta WordPress-közremƱködƑk – 1.6.2 Product Feed PRO for WooCommerce: Ă­rta AdTribes.io – 11.1.4 Woocommerce Customers Order History: Ă­rta javmah – 5.2.0 Barion Payment Gateway for WooCommerce: Ă­rta Peter Szel – 3.4.0 Booster for WooCommerce: Ă­rta Pluggabl LLC – 5.5.0 Customer Reviews for WooCommerce: Ă­rta CusRev – 4.35 Disable WooCommerce Bloat: Ă­rta ospiotr – 2.6.1 Heartbeat Control by WP Rocket: Ă­rta WP Rocket – 2.0 HuCommerce | Magyar WooCommerce kiegĂ©szĂ­tĂ©sek: Ă­rta HuCommerce.hu – 30.2.0 Integration for Billingo & WooCommerce: Ă­rta PWS Online Kft. – 3.3.2 Loco Translate: Ă­rta Tim Whitlock – 2.5.7 Rank Math SEO: Ă­rta Rank Math – 1.0.80 Tibi Email attachment plugin: Ă­rta Tibi – 1.0.0 Very Simple Contact Form: Ă­rta Guido – 11.4 WooCommerce: Ă­rta Automattic – 6.1.0 WooCommerce DPD Weblabel Export: Ă­rta Viszt PĂ©ter – 1.0.1 WooCommerce Google Analytics Integration: Ă­rta WooCommerce – 1.5.7 Limit Login Attempts Reloaded: Ă­rta Limit Login Attempts Reloaded – 2.23.2 Hummingbird: Ă­rta WPMU DEV – 3.2.1 Akismet Anti-Spam: Ă­rta Automattic – 4.2.1 ### Inactive Plugins (8) ### Facebook for WooCommerce: Ă­rta Facebook – 2.6.9 Nextend Social Login: Ă­rta Nextendweb – 3.1.3 Page Links To: Ă­rta Mark Jaquith – 3.3.6 Pixel Caffeine: Ă­rta AdEspresso – 2.3.3 Query Monitor: Ă­rta John Blackbourn – 3.8.2 Smush: Ă­rta WPMU DEV – 3.9.4 WP Rollback: Ă­rta Impress.org – 1.7.1 WP WooCommerce Mailchimp: Ă­rta Saint Systems – 2.4.8 ### Dropin Plugins (1) ### advanced-cache.php: advanced-cache.php ### Must Use Plugins (2) ### installatron_hide_status_test.php: Ă­rta – WordPress automation by Installatron: Ă­rta – ### Settings ### API Enabled: – Force SSL: – Currency: HUF (Ft) Currency Position: right_space Thousand Separator: , Decimal Separator: . Number of Decimals: 0 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to WooCommerce.com: – ### WC Pages ### Webshop fƑoldal: #4 - /termekek/ KosĂĄr: #5 - /kosar/ PĂ©nztĂĄr: #6 - /penztar/ A fiĂłkom: #7 - /sajat-fiok/ ÁltalĂĄnos SzerzƑdĂ©si FeltĂ©telek: ❌ Az oldal nincs beĂĄllĂ­tva ### Theme ### Name: Flatsome Child Theme Version: 2.5 Author URL: http:%20//www.uxthemes.com/ Child Theme: ✔ Parent Theme Name: Flatsome Parent Theme Version: 3.14.3 Parent Theme Author URL: http://www.uxthemes.com/ WooCommerce Support: ✔ ### Templates ### Overrides: flatsome/woocommerce/archive-product.php flatsome/woocommerce/cart/cart-empty.php flatsome/woocommerce/cart/cart-shipping.php flatsome/woocommerce/cart/cart.php flatsome/woocommerce/checkout/form-checkout.php flatsome/woocommerce/checkout/form-coupon.php flatsome/woocommerce/checkout/terms.php flatsome/woocommerce/checkout/thankyou.php flatsome/woocommerce/content-product-cat.php flatsome/woocommerce/content-product.php flatsome/woocommerce/content-single-product.php flatsome/woocommerce/content-widget-product.php flatsome-eletso/woocommerce/emails/customer-completed-order.php flatsome-eletso/woocommerce/emails/customer-note.php flatsome-eletso/woocommerce/emails/customer-processing-order.php flatsome/woocommerce/global/breadcrumb.php flatsome/woocommerce/global/quantity-input.php flatsome/woocommerce/global/wrapper-end.php flatsome/woocommerce/global/wrapper-start.php flatsome/woocommerce/loop/loop-end.php flatsome/woocommerce/loop/loop-start.php flatsome/woocommerce/loop/pagination.php flatsome/woocommerce/loop/result-count.php flatsome/woocommerce/loop/sale-flash.php flatsome/woocommerce/myaccount/form-login.php flatsome/woocommerce/myaccount/navigation.php flatsome/woocommerce/notices/error.php flatsome/woocommerce/notices/notice.php flatsome/woocommerce/notices/success.php flatsome/woocommerce/product-searchform.php flatsome/woocommerce/single-product/photoswipe.php flatsome/woocommerce/single-product/price.php flatsome/woocommerce/single-product/product-image.php flatsome/woocommerce/single-product/product-thumbnails.php flatsome/woocommerce/single-product/rating.php flatsome/woocommerce/single-product/related.php flatsome/woocommerce/single-product/review.php flatsome/woocommerce/single-product/sale-flash.php flatsome/woocommerce/single-product/share.php flatsome/woocommerce/single-product/short-description.php flatsome/woocommerce/single-product/tabs/tabs.php flatsome/woocommerce/single-product/title.php flatsome/woocommerce/single-product/up-sells.php flatsome/woocommerce/single-product-reviews.php flatsome/woocommerce/single-product.php flatsome/woocommerce/content-product_cat.php ### Action Scheduler ### Complete: 269 Oldest: 2022-01-08 14:27:56 +0000 Newest: 2022-01-18 13:25:59 +0000 Pending: 1 Oldest: 2022-01-19 12:25:48 +0000 Newest: 2022-01-19 12:25:48 +0000 ### Status report information ### Generated at: 2022-01-19 14:17:37 +02:00 `
nicdwilson commented 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?

futyko commented 2 years ago

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!

jconroy commented 2 years ago

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?

JimmyAppelt commented 2 years ago

@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:

  1. save the global post
  2. process
  3. reset the global post

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;
futyko commented 2 years ago

@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."

mattermarketing commented 2 years ago

We've also disabled the sync as per the other threads. It is still misbehaving.

JimmyAppelt commented 2 years ago

@rawdreeg You're welcome 🙂

rawdreeg commented 2 years ago

Thanks @JimmyAppelt for the detailed explanation 😊 Helped a ton 😀

JimmyAppelt commented 2 years ago

Thanks @JimmyAppelt for the detailed explanation 😊 Helped a ton 😀

@rawdreeg thank you for applying a workaround in the plugin core 🙂