Skip to content
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

Prevent "woocommerce_new_order" from being triggered on orders with "checkout-draft" status #47422

Open
wants to merge 16 commits into
base: trunk
Choose a base branch
from

Conversation

wavvves
Copy link
Contributor

@wavvves wavvves commented May 13, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR prevents "woocommerce_new_order" action from being triggered when visiting the Checkout Block page, while the order status is "checkout-draft".

Closes #45145 .

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Install the Code Snippets extension and add the following snippet:
add_action("woocommerce_new_order","any",20,1);
function any($order_id){
    ob_get_clean();
    die("woocommerce_new_order was triggered");
}
  1. If your cart has items make sure to place a new order
  2. Add item(s) to your cart and visit the checkout blocks page
  3. Verify the checkout page displays correctly and the text "woocommerce_new_order was triggered" is not displayed

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Prevent "woocommerce_new_order" from being triggered on orders with "checkout-draft" status

Comment

@wavvves wavvves linked an issue May 13, 2024 that may be closed by this pull request
5 tasks
@wavvves wavvves self-assigned this May 13, 2024
@wavvves wavvves requested a review from vedanshujain May 13, 2024 16:43
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 13, 2024
@woocommercebot woocommercebot requested review from a team and nielslange and removed request for a team May 13, 2024 16:43
@wavvves wavvves added type: bug The issue is a confirmed bug. team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues labels May 13, 2024
Copy link
Contributor

github-actions bot commented May 13, 2024

Hi @opr, @senadir, @vedanshujain,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@wavvves wavvves marked this pull request as draft May 13, 2024 16:43
@wavvves wavvves marked this pull request as ready for review May 13, 2024 16:43
@woocommercebot woocommercebot requested a review from a team May 13, 2024 16:43
@wavvves wavvves removed request for nielslange and a team May 13, 2024 16:44
@wavvves wavvves marked this pull request as draft May 13, 2024 16:45
@wavvves wavvves marked this pull request as ready for review May 13, 2024 16:46
@woocommercebot woocommercebot requested review from a team and opr and removed request for a team May 13, 2024 16:46
Copy link
Contributor

github-actions bot commented May 13, 2024

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

Copy link
Member

@senadir senadir left a comment

Choose a reason for hiding this comment

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

Wanted to get this PR merged today but it's still missing too many things.

The code only applies to HPOS stores, not regular stores (see code).
It fails to trigger the new order hook for orders that were previously draft (see code and this code).

@wavvves wavvves added priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. and removed priority: high The issue/PR is high priority—it affects lots of customers substantially, but not critically. labels May 23, 2024
@wavvves
Copy link
Contributor Author

wavvves commented May 27, 2024

Wanted to get this PR merged today but it's still missing too many things.

The code only applies to HPOS stores, not regular stores (see code). It fails to trigger the new order hook for orders that were previously draft (see code and this code).

Not sure I follow this, there's no consideration for status strings on the linked example (create order), and the new order action seems to be triggered disregarding the status.

For the other example (since one has a broken link, and there's no referenced lines if I try to fix it), I agree with you, it is not considering moving the order from checkout-draft, I added it 3f959f6

Can you please elaborate on the other two Nadir? Thanks in advance :)

@github-actions github-actions bot added the package: @woocommerce/components issues related to @woocommerce/components label May 27, 2024
@wavvves wavvves requested a review from senadir May 27, 2024 14:52
@wavvves wavvves added the needs: discussion Issue that either needs discussion or pending decision (not for support requests). label May 27, 2024
Copy link
Contributor

@vedanshujain vedanshujain left a comment

Choose a reason for hiding this comment

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

@wavvves I think what @senadir is referring to here is we would want two separate changes:

  1. Not trigger the woocommerce_new_order hook when the status is one of the draft ones. You are already doing this for HPOS but not for CPT.
  2. Do trigger this hook, when the status is changed from a draft one to a non draft one. You are doing this for CPT but not for HPOS.

Essentially, we should:

Additionally, we should probably make the list of draft statuses consistent, plus maybe add some unit tests around these flows. wdyt?

@senadir
Copy link
Member

senadir commented May 28, 2024

Yeah that's exactly what I had in mind @vedanshujain , just more elegantly from your side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: discussion Issue that either needs discussion or pending decision (not for support requests). package: @woocommerce/components issues related to @woocommerce/components plugin: woocommerce Issues related to the WooCommerce Core plugin. team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues type: bug The issue is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

woocommerce_new_order triggers on checkout visiting
3 participants