-
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
Ensure coupon brand restrictions are uploaded to Google Merchant Center. #2697
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2697 +/- ##
============================================
+ Coverage 63.4% 66.2% +2.8%
- Complexity 0 4691 +4691
============================================
Files 340 479 +139
Lines 5210 19603 +14393
Branches 1275 0 -1275
============================================
+ Hits 3305 12984 +9679
- Misses 1730 6619 +4889
+ Partials 175 0 -175
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Thanks for the good catch @eason9487. I've updated the PR and it's ready for another round. |
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.
Thanks for the work. Tested that the brand restrictions of coupons can be converted to product IDs and then synced to Google Merchant Center.
However, just noticed there may be another concern. If a product is later created/updated to attach or detach a brand having associations with coupon restrictions, the brand restrictions (converted to associated product IDs) of those coupons won't be synced.
Thanks for catching this case @eason9487. I've updated the code to take care of this scenario and have also updated the testing instruction in the PR. However, I did not solve the case when the product is deleted/trashed, so when it happens the GMC promotion filters will still have the deleted product IDs included. This is align with the behaviour of the coupon product inclusion restriction (not the brand restriction) - i.e. when a coupon has an included product restriction, then the product gets deleted, GMC promotion filters still have that product. |
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.
Thanks for the further update! Tested that coupon brand restrictions can be converted to associated product IDs and be synchronized to GMC. LGTM.
The mismatched code comment should not need another round.
Changes proposed in this Pull Request:
Closes #2693.
Since WooCommerce 9.4, WooCommerce Brands is now part of the WooCommerce core, the merchant can add brand restrictions when editing coupons, but G4W plugin does not upload the corresponding coupon brand restrictions to Google Merchant Center.
This PR adds coupon restrictions for brands when generating the coupon (promotions) payload for updating to Google Merchant Center.
Note that
WC_Coupon
class does not have a method to get the brand restrictions like other restrictions do. This PR uses get_post_meta() to get the brands from a coupon, then uses get_objects_in_term() to get a list of product IDs from that brand.Refer to the following tables to better understand the data:
wp_postmeta
get_post_meta()
product_brands
andexclude_product_brands
wp_terms
wp_term_taxonomy
product_brand
)wp_term_relationships
get_objects_in_term()
product_brand
inget_objects_in_term()
Updated 28th Nov
For querying brands from a coupon from post_meta, I found in class-wc-brands-brand-settings-manager.php I can use it like:
However, since we do not expect all merchants update to latest WooCommerce, we also need to ensure backward compatibility for those who still use WC Brands plugin. The code above was available since WC Brands plugin version 1.6.65, so I lean towards to still querying post_meta manually as it's safest for all version and in core.
Screenshots:
Detailed test instructions:
wc_feature_woocommerce_brands_enabled
andwoocommerce_remote_variant_assignment
wp option update wc_feature_woocommerce_brands_enabled 'yes' wp option update woocommerce_remote_variant_assignment 2
Products > Brands
, e.g.Screen.Recording.2024-11-27.at.15.07.31.mov
WooCommerce > Status > Scheduled Actions
, search for the jobgla/jobs/update_coupon/process_item
, run it manually if it is still pending to save timeScreen.Recording.2024-11-27.at.15.24.52.mov
Product added or removed from a brand
Test Brand 1
and update the productWooCommerce > Status > Scheduled Actions
, search for the jobgla/jobs/update_coupon/process_item
, run it manually if it is still pending to save timeTest Brand 1
back. You should see the product gets synced to GMC in the coupon filters again.Test Brand 1
, you should see the product gets synced to GMC in the coupon filters again.Additional details:
Changelog entry