Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Introduce 2 new hooks in Customer Update Route #5345

Merged
merged 4 commits into from
Dec 13, 2021
Merged

Introduce 2 new hooks in Customer Update Route #5345

merged 4 commits into from
Dec 13, 2021

Conversation

mikejolley
Copy link
Member

@mikejolley mikejolley commented Dec 9, 2021

Adds 2 new action hooks to allow vendors to edit order/customer data when customers are updated via the API.

Hook Description Params
woocommerce_blocks_cart_update_customer_from_request Fires when the Checkout Block/Store API updates a customer from the API request data. \WC_Customer $customer, \WP_REST_Request $request
woocommerce_blocks_cart_update_order_from_customer_request Fires when the Checkout Block/Store API updates an existing draft order from customer data. \WC_Order $draft_order, \WC_Customer $customer, \WP_REST_Request $request

Fixes #5202

Testing

No user facing tests. Unit test coverage added to confirm hooks fire.

Changelog

StoreAPI - Introduce woocommerce_blocks_cart_update_customer_from_request and woocommerce_blocks_cart_update_order_from_customer_request hooks in the StoreAPI.

@mikejolley mikejolley self-assigned this Dec 9, 2021
@rubikuserbot rubikuserbot requested review from a team and alexflorisca and removed request for a team December 9, 2021 09:57
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2021

Size Change: -23.6 kB (-3%)

Total Size: 817 kB

Filename Size Change
build/active-filters-frontend.js 6.22 kB +1 B (0%)
build/all-products-frontend.js 18.6 kB +51 B (0%)
build/atomic-block-components/add-to-cart-frontend.js 6.86 kB -16 B (0%)
build/atomic-block-components/button-frontend.js 1.48 kB +2 B (0%)
build/atomic-block-components/category-list-frontend.js 457 B -1 B (0%)
build/atomic-block-components/image-frontend.js 1.37 kB -2 B (0%)
build/atomic-block-components/price-frontend.js 1.74 kB -2 B (0%)
build/atomic-block-components/rating-frontend.js 552 B -1 B (0%)
build/atomic-block-components/sale-badge-frontend.js 625 B -1 B (0%)
build/atomic-block-components/stock-indicator-frontend.js 584 B -1 B (0%)
build/atomic-block-components/summary-frontend.js 872 B -3 B (0%)
build/atomic-block-components/tag-list-frontend.js 458 B -1 B (0%)
build/atomic-block-components/title-frontend.js 1.11 kB +1 B (0%)
build/attribute-filter-frontend.js 16.3 kB -278 B (-2%)
build/blocks-checkout.js 17.6 kB +7 B (0%)
build/cart-blocks/accepted-payment-methods-frontend.js 1.15 kB +4 B (0%)
build/cart-blocks/express-payment-frontend.js 4.88 kB +14 B (0%)
build/cart-blocks/filled-cart-frontend.js 766 B -1 B (0%)
build/cart-blocks/items-frontend.js 298 B +1 B (0%)
build/cart-blocks/line-items-frontend.js 5.12 kB -15 B (0%)
build/cart-blocks/order-summary-frontend.js 8.98 kB +18 B (0%)
build/cart-frontend.js 45.4 kB -41 B (0%)
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.24 kB -4 B (0%)
build/checkout-blocks/billing-address-frontend.js 884 B -3 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.93 kB -12 B (0%)
build/checkout-blocks/express-payment-frontend.js 5.17 kB +2 B (0%)
build/checkout-blocks/order-note-frontend.js 1.13 kB -1 B (0%)
build/checkout-blocks/order-summary-frontend.js 11.4 kB -35 B (0%)
build/checkout-blocks/payment-frontend.js 7.46 kB -20 B (0%)
build/checkout-blocks/shipping-address-frontend.js 971 B -2 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 4.8 kB -4 B (0%)
build/checkout-blocks/totals-frontend.js 324 B +1 B (0%)
build/checkout-frontend.js 47.5 kB -24 B (0%)
build/mini-cart-component-frontend.js 14.2 kB -23.4 kB (-62%) 🏆
build/mini-cart-contents.js 3.45 kB -3 B (0%)
build/mini-cart-frontend.js 1.76 kB +3 B (0%)
build/price-filter-frontend.js 12.4 kB +31 B (0%)
build/product-on-sale.js 8.05 kB -1 B (0%)
build/reviews-frontend.js 7.25 kB +14 B (0%)
build/single-product-frontend.js 22.1 kB +124 B (+1%)
build/stock-filter-frontend.js 6.81 kB +13 B (0%)
build/vendors--atomic-block-components/add-to-cart--cart-blocks/order-summary--checkout-blocks/billing-ad--c5eb4dcd-frontend.js 18.9 kB +4 B (0%)
build/vendors--atomic-block-components/add-to-cart-frontend.js 6.82 kB +3 B (0%)
build/vendors--atomic-block-components/price--cart-blocks/line-items--cart-blocks/order-summary--checkout--8a3571de-frontend.js 5.71 kB +1 B (0%)
build/vendors--cart-blocks/line-items--checkout-blocks/order-summary-frontend.js 3.14 kB +1 B (0%)
build/vendors--cart-blocks/order-summary--checkout-blocks/billing-address--checkout-blocks/order-summary---eb4d2cec-frontend.js 4.75 kB +2 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters.js 7.06 kB
build/all-products.js 34.4 kB
build/all-reviews.js 8.35 kB
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/image---a7e2bb9b.js 2.76 kB
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 1.48 kB
build/atomic-block-components/add-to-cart.js 6.42 kB
build/atomic-block-components/button.js 848 B
build/atomic-block-components/category-list.js 458 B
build/atomic-block-components/image.js 1.05 kB
build/atomic-block-components/price.js 1.69 kB
build/atomic-block-components/rating.js 553 B
build/atomic-block-components/sale-badge.js 622 B
build/atomic-block-components/sku-frontend.js 386 B
build/atomic-block-components/sku.js 385 B
build/atomic-block-components/stock-indicator.js 586 B
build/atomic-block-components/summary.js 872 B
build/atomic-block-components/tag-list.js 458 B
build/atomic-block-components/title.js 1.1 kB
build/attribute-filter.js 12.7 kB
build/cart-blocks/checkout-button-frontend.js 1.14 kB
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/totals-frontend.js 320 B
build/cart.js 44 kB
build/checkout-blocks/actions-frontend.js 1.45 kB
build/checkout-blocks/fields-frontend.js 343 B
build/checkout-blocks/terms-frontend.js 1.22 kB
build/checkout.js 47 kB
build/featured-category.js 8.55 kB
build/featured-product.js 9.9 kB
build/handpicked-products.js 7.33 kB
build/legacy-template.js 2.08 kB
build/mini-cart.js 6.65 kB
build/price-filter.js 8.61 kB
build/price-format.js 1.18 kB
build/product-best-sellers.js 7.51 kB
build/product-categories.js 3.47 kB
build/product-category.js 8.36 kB
build/product-new.js 7.67 kB
build/product-search.js 2.47 kB
build/product-tag.js 7.77 kB
build/product-top-rated.js 7.63 kB
build/products-by-attribute.js 8.49 kB
build/reviews-by-category.js 11.9 kB
build/reviews-by-product.js 12.9 kB
build/single-product.js 10.4 kB
build/stock-filter.js 6.83 kB
build/wc-blocks-data.js 8.84 kB
build/wc-blocks-editor-style-rtl.css 4.3 kB
build/wc-blocks-editor-style.css 4.31 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 949 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-shared-context.js 1.51 kB
build/wc-blocks-shared-hocs.js 1.14 kB
build/wc-blocks-style-rtl.css 21.1 kB
build/wc-blocks-style.css 21.1 kB
build/wc-blocks-vendors-style-rtl.css 1.28 kB
build/wc-blocks-vendors-style.css 1.28 kB
build/wc-blocks-vendors.js 65.5 kB
build/wc-blocks.js 2.96 kB
build/wc-payment-method-bacs.js 820 B
build/wc-payment-method-cheque.js 816 B
build/wc-payment-method-cod.js 912 B
build/wc-payment-method-paypal.js 838 B
build/wc-payment-method-stripe.js 11.1 kB
build/wc-settings.js 2.6 kB

compressed-size-action

@alexflorisca
Copy link
Member

Is there any documentation we should update with these new hooks? Also is there a way to test that these fire correctly?

Code looks good, although with a caveat that I haven't done any PHP for 10 years!

@mikejolley
Copy link
Member Author

@alexflorisca I've added unit tests to confirm the hooks run, and updated hook docs (npm run build:docs). Should be good now 👍🏻

Copy link
Member

@alexflorisca alexflorisca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good, but there seem to be a bunch of duplicated entries and a lot of changes made to the docs unrelated to the 2 hooks you added here. Can you just have a scan through and double check that everything is good doc wise, and if you're happy, I'm happy to approve.

}
},
{
"name": "woocommerce_after_main_content",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate of the above. It's also unrelated to the hooks you added in this PR. Is this something that exists but was missing from the docs?

}
},
{
"name": "woocommerce_before_main_content",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again this seems to be the same as the one above, with a minor difference in the description and an extra tag. Just checking this is intended?

{
"name": "woocommerce_blocks_cart_enqueue_data",
"file": "BlockTypes/Cart.php",
"file": "BlockTypes/MiniCart.php",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has the Cart and MiniCart swapped round here and on the action below?

Copy link
Member

@alexflorisca alexflorisca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in slack (p1639399554056600-slack-C8X6Q7XQU) and decided to ignore the duplicated actions for now (bug reported in #5374)

@github-actions github-actions bot added this to the 6.6.0 milestone Dec 13, 2021
@mikejolley mikejolley merged commit cda1bae into trunk Dec 13, 2021
@mikejolley mikejolley deleted the fix/5202 branch December 13, 2021 13:57
jonny-bull pushed a commit to jonny-bull/woocommerce-gutenberg-products-block that referenced this pull request Dec 14, 2021
* Introduce woocommerce_blocks_cart_update_customer_from_request hook

* Introduce woocommerce_blocks_cart_update_order_from_customer_request

* Test actions fire

* Update hook docs
jonny-bull pushed a commit to jonny-bull/woocommerce-gutenberg-products-block that referenced this pull request Dec 16, 2021
* Introduce woocommerce_blocks_cart_update_customer_from_request hook

* Introduce woocommerce_blocks_cart_update_order_from_customer_request

* Test actions fire

* Update hook docs
@mikejolley mikejolley added the skip-changelog PRs that you don't want to appear in the changelog. label Dec 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip-changelog PRs that you don't want to appear in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

woocommerce_blocks_checkout_update_order_from_request doesn't trigger for customer email.
2 participants