-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't sync invisible products to MC #880
Conversation
The `ProductHelper::is_sync_ready` method now also checks whether a product is visible. It will mark a product as NOT sync ready if: - `woocommerce_hide_out_of_stock_items` option is enabled and the product is out of stock - If it's an invisible variation (i.e. have no price or it's disabled) The WooCommerce core `woocommerce_hide_invisible_variations` filter is also used here to check whether the variation should be hidden if it's invisible.
I see @layoutd was already checking this PR. But on regular products why aren't we using the |
Yeah, I first wanted to use that one but the issue is that the Since we have our own I guess the question is do we want to sync products based on the "catalog visibility" option? cc: @j111q |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍🏻 . The test instructions all worked as expected and, when I finally got PHP back up and running, the unit tests did, too.
Should be ready to merge, pending the final decision on catalog_visibility
.
Please hide it if it's set to I have not heard a use case where they'd want to hide from their store but show on Google. That would be really confusing for users coming from Google to their store too. I have heard users mention how they've gone to lengths such as: Setting to Hidden in Catalog, AND turning it into a Draft, AND setting it as out of stock just to make sure it doesn't appear anywhere at all. |
Checks if a product is sync-ready based on the visibility value returned by the `\WC_Product::is_visible` method. This method the `catalog_visibility` option along with a few other properties and filters to see if a product is visible in the shop.
Thanks for the review, @layoutd, and for your inputs, @mikkamp, and @j111q 🙏 I've modified the code to also account for catalog visibility when checking if a product is sync-ready (by making use of the @j111q Should we still allow a product's channel visibility to be set to |
In my mind, ideally we should:
Is this possible to do, or is that too complicated? 😅 I do realise it expands the scope of this issue quite a bit. |
The select box is disabled on the backend and can only be enabled if the product catalog visibility changes to visible and the product is saved to DB.
I've made some changes to disabled the channel visibility select box if the product isn't visible: Since WooCommerce doesn't provide a JS event when the catalog visibility value is modified (and I didn't want to bind on any inputs since they may change), the select box is disabled on the backend side, which means that if the catalog visibility is modified it would not enable the channel visibility unless the product is saved and the page is reloaded. Modifying the Channel Visibility value to "Don't Sync & Show" also means that this value is saved to DB once the user saves a product. This means that if the user changes the catalog visibility value back to @layoutd Could you please give the new changes another review/testing? Testing Instructions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 The latest changes work fine and the catalog visibility is also taken into account when syncing (along with stock quantity and the out of stock visibility setting).
Small nit: I noticed that the "Google sync status" box is still visible sometimes when the GLA channel visibility is forced to Don't Sync and show
:
This happens if:
- A product is set to visible in the catalog (
Shop and search results
, orShop only
), the GLA channel visibility isSync and show
, and the product is saved. - Then the catalog visibility is set to hidden (
Search results only
orHidden
) and the product is saved.
The GLA channel visibility box is then disabled correctly, but I believe the actual postmeta
value is still sync-and-show
, so the "Google sync status - Not synced" message is still displayed.
This isn't the case if the product is manually set to Don't Sync and show
first, before the channel visibility is changed to hidden:
I think adding $show_status = false
in the is_visible()
conditional would resolve it:
https://github.com/woocommerce/google-listings-and-ads/pull/880/files#diff-64e0d8a3cf27a82c2419d94905e0e75e4c317c431cee268733ff969feacf6573R48-R52
Yes, this is fine IMO. Thanks for this @nima-karimi! |
Changes proposed in this Pull Request:
This PR modifies the
ProductHelper::is_sync_ready
method so that it also checks the product's visibility. In addition to the previous conditions, it now returns false for a product when:woocommerce_hide_out_of_stock_items
option is enabled and the product is out of stockThe WooCommerce core
woocommerce_hide_invisible_variations
filter is also used here to check whether the variation should be displayed even if it's invisible.These conditions were already checked for variations in
SyncerHooks
class and a few other places where the method accepts a variable product and tries to fetch its "available" variations via the\WC_Product_Variable::get_available_variations
method. By adding these conditions toProductHelper::is_sync_ready
we'll also check for the "availability" (or visibility) of all other product types just like we do for variations and make things more consistent.One major effect of this change is that if the user has enabled the
woocommerce_hide_out_of_stock_items
we no longer sync theout-of-stock
products to Merchant Center and also remove the previously synced products once the product goes out of stock.However, if the user already has some out-of-stock products and then enables the
woocommerce_hide_out_of_stock_items
option, we do not remove anything. This should probably be done by watching the WooCommerce events and trigger a refresh job if any settings change. I didn't include this part in the PR because we also don't do this for any other settings changes (e.g. country, language, etc.) and I first wanted to discuss whether we need to.Detailed test instructions:
Out of stock visibility
option under "WooCommerce > Settings > Products > Inventory"Out of stock visibility
option under "WooCommerce > Settings > Products > Inventory"Changelog entry