Skip to content

Fix: send the active price to Square, not a stored sale price outside its sale dates - #606

Open
Provello wants to merge 1 commit into
woocommerce:trunkfrom
Provello:fix/sync-active-price-not-stored-sale-price
Open

Provello wants to merge 1 commit into
woocommerce:trunkfrom
Provello:fix/sync-active-price-not-stored-sale-price

Conversation

@Provello

Copy link
Copy Markdown

All Submissions:

  • Does your code follow the WooCommerce Sniffs variant of WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Will this change require new documentation or changes to existing documentation?

Changes proposed in this Pull Request:

With WooCommerce as system of record, Woo_SOR::update_catalog_variation() sends get_sale_price() ?: get_regular_price(). The stored sale price is sent whenever it exists, with no check of the sale dates.

Since WooCommerce 10.5.0, core no longer clears sale_price when a scheduled sale ends (wc_apply_sale_state_for_product() only sets price back). So after every scheduled sale, Square keeps charging the sale price while the store charges the regular price. A re-sync sends the stale sale price again. The same line also sends a sale price to Square before a future-dated sale has started.

This PR:

  1. Adds Woo_SOR::get_active_price() and uses it for price_money. The sale price is sent only while is_on_sale() is true. Two existing behaviours are kept: a product with only a sale price still sends it, and a product with no price still sends 0.
  2. Stages the product for sync when core starts or ends a scheduled sale (wc_product_start_scheduled_sale, wc_product_end_scheduled_sale, and the daily wc_after_products_starting_sales / wc_after_products_ending_sales), at priority 20, after core has applied the price at 10. A variation is staged through its parent, because saving a variation does not fire woocommerce_update_product. maybe_stage_product_for_sync() already de-duplicates within a request, so a simple product that core has just saved is not staged twice.

Not in this PR: a one-time re-push for stores that already hold stale prices in Square. Those need a re-sync after the update. Happy to add an upgrade routine if you want one.

Closes #605.

Steps to test the changes in this Pull Request:

  1. WooCommerce as system of record. Simple product synced with Square, regular price 100.
  2. Set sale price 80 with a "sale to" date in the past (or set a near end date and let it pass). Save.
  3. On trunk: the Square variation price is 80. On this branch: 100.
  4. Set a "sale from" date in the future instead. On trunk: Square is 80 at once. On this branch: 100 until the sale starts, then 80.
  5. Sale with no dates, or inside its date window: Square is 80 on both.
  6. composer test-unit -- --filter Woo_SOR_Active_Price_Test

Changelog entry

Fix - Square is no longer sent a sale price after a scheduled sale has ended, or before it has started.

🤖 Generated with Claude Code

…sale dates

With WooCommerce as system of record, update_catalog_variation() sent
get_sale_price() ?: get_regular_price(), with no check of the sale dates.
WooCommerce 10.5.0+ keeps sale_price on the product after a scheduled sale
ends, so Square kept charging the sale price. A sale scheduled for the
future was also sent to Square before it started.

- Add Woo_SOR::get_active_price() and use it for price_money.
- Stage the product for sync when core starts or ends a scheduled sale.
  A variation is staged through its parent.
- Unit tests for the price choice.

Fixes woocommerce#605

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expired (or not yet started) scheduled sale price is pushed to Square as the item price

1 participant