woocommerce / woocommerce

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
https://woocommerce.com
9.34k stars 10.76k forks source link

Order api update contradicts with custom options #38222

Open sudipto-me opened 1 year ago

sudipto-me commented 1 year ago

Prerequisites

Describe the bug

I am using the Woocommerce REST API for placing orders on my webshop. I have added some custom additional fields to the Woocommerce order API. While creating an order, I can check the field validations and prevent the creation of an order via API if the conditions are not met. However, when updating an order, if I check the field validations and create an error for a specific validation, other options are still updated via API. For example, if I provide 5 values in the JSON payload where 3 are correct and 2 are not, the API updates the 3 correct ones and returns a 200 status code, even though the other 2 are not updated. I want the API to not update any of the fields if any of them are incorrect. I have checked the Woocommerce core and have not found a solution to this issue.

Expected behavior

Like creating an order if all the conditions are valid then it should return 2xx code. And if the one of the conditions are not valid, should return 4xx code. If any validations are failed then other updates should not be perform.

Actual behavior

It updates whether any 4xx code returns.

Steps to reproduce

Here I add some code samples from my codebase: add_filter( 'woocommerce_rest_pre_insert_shop_order_object', array( CLASS, 'customize_order_update_through_api' ), 10, 3 ); `/**

WordPress Environment

`

WordPress Environment

WordPress address (URL): https://woocommerce-882319-3071162.cloudwaysapps.com Site address (URL): https://woocommerce-882319-3071162.cloudwaysapps.com WC Version: 7.4.1 REST API Version: ✔ 7.4.1 WC Blocks Version: ✔ 9.4.4 Action Scheduler Version: ✔ 3.5.4 Log Directory Writable: ✔ WP Version: 6.2 WP Multisite: – WP Memory Limit: 512 MB WP Debug Mode: ✔ WP Cron: ✔ Language: en_US External object cache: ✔

Server Environment

Server Info: Apache/2.4.55 (Debian) PHP Version: 7.4.33 PHP Post Max Size: 100 MB PHP Time Limit: 300 PHP Max Input Vars: 10000 cURL Version: 7.64.0 OpenSSL/1.1.1n

SUHOSIN Installed: – MySQL Version: 5.5.5-10.4.20-MariaDB-1:10.4.20+maria~buster-log Max Upload Size: 100 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔

Database

WC Database Version: 7.4.0 WC Database Prefix: wp_ Total Database Size: 120.56MB Database Data Size: 103.84MB Database Index Size: 16.72MB wp_woocommerce_sessions: Data: 0.33MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_order_itemmeta: Data: 1.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_actions: Data: 3.02MB + Index: 1.88MB + Engine InnoDB wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_actionscheduler_logs: Data: 2.02MB + Index: 1.47MB + Engine InnoDB wp_bv_fw_requests: Data: 2.52MB + Index: 0.00MB + Engine InnoDB wp_bv_ip_store: Data: 0.38MB + Index: 0.34MB + Engine InnoDB wp_bv_lp_requests: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB wp_fsmpt_email_logs: Data: 14.02MB + Index: 0.00MB + Engine InnoDB wp_gdpr_cc_options: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_gglcptch_allowlist: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mclean_refs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_mclean_scan: Data: 0.19MB + Index: 0.05MB + Engine InnoDB wp_options: Data: 4.09MB + Index: 0.36MB + Engine InnoDB wp_postmeta: Data: 51.17MB + Index: 2.08MB + Engine InnoDB wp_posts: Data: 2.09MB + Index: 0.13MB + Engine InnoDB wp_realmedialibrary: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_realmedialibrary_meta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_realmedialibrary_posts: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_realmedialibrary_tmp: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_simple_history: Data: 2.19MB + Index: 0.55MB + Engine InnoDB wp_simple_history_contexts: Data: 11.02MB + Index: 8.16MB + Engine InnoDB wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_usermeta: Data: 1.06MB + Index: 0.03MB + Engine InnoDB wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wcpdf_invoice_number: Data: 0.08MB + Index: 0.00MB + Engine InnoDB wp_wcpdf_packing_slip_number: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_admin_notes: Data: 0.06MB + Index: 0.00MB + Engine InnoDB wp_wc_admin_note_actions: Data: 0.06MB + Index: 0.02MB + Engine InnoDB wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.05MB + Index: 0.09MB + Engine InnoDB wp_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wfblockediplog: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfblocks7: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wfconfig: Data: 0.47MB + Index: 0.00MB + Engine InnoDB wp_wfcrawlers: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wffilechanges: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wffilemods: Data: 2.52MB + Index: 0.00MB + Engine InnoDB wp_wfhits: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wfhoover: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wfissues: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wfknownfilelist: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_wflivetraffichuman: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wflocs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wflogins: Data: 0.05MB + Index: 0.03MB + Engine InnoDB wp_wfls_2fa_secrets: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wfls_settings: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfnotifications: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfpendingissues: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wfreversecache: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wfsnipcache: Data: 0.02MB + Index: 0.05MB + Engine InnoDB wp_wfstatus: Data: 0.13MB + Index: 0.09MB + Engine InnoDB wp_wftrafficrates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpfm_backup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpmailsmtp_debug_events: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpmailsmtp_tasks_meta: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpml_mails: Data: 2.52MB + Index: 0.00MB + Engine InnoDB

Post Type Counts

announcer: 1 attachment: 187 custom_css: 1 customize_changeset: 5 nav_menu_item: 31 page: 19 post: 4 revision: 30 shop_order_refund: 15 vrbn-job: 1 vrbn-media: 10 vrbn-partner: 4 vrbn-reference: 12 vrbn-section: 40 vrbn-showcase: 6 vrbn-team: 3 vrbn-testimonial: 6 wmpc-trash: 50 wp_global_styles: 1

Security

Secure connection (HTTPS): ✔ Hide errors from visitors: ✔

Active Plugins (18)

Classic Editor: by WordPress Contributors – 1.6.3 Email Address Encoder: by Till Krüss – 1.0.22 FluentSMTP: by FluentSMTP & WPManageNinja Team – 2.2.4 GDPR Cookie Compliance: by Moove Agency – 4.11.1 reCaptcha by BestWebSoft: by BestWebSoft – 1.70 MalCare WordPress Security Plugin - Malware Scanner, Cleaner, Security Firewall: by MalCare Security – 4.97 Pop-up Notices for WooCommerce: by WPFactory – 1.4.1 SVG Support: by Benbodhi – 2.5.5 User Switching: by John Blackbourn & contributors – 1.7.0 Vrbn API: by Selise – 1.0.0 vrbn Price Converter: by Selise – 1.0.0 WooCommerce Media API: by woopos – 2.8 WooCommerce Stripe Gateway: by WooCommerce – 7.3.0 PDF Invoices & Packing Slips for WooCommerce: by WP Overnight – 3.5.2 WooCommerce: by Automattic – 7.4.1 (update to version 7.7.0 is available) WP Browser Platform Detection: by Gourav RR – 2.0.0 WP File Manager: by mndpsingh287 – 7.1.8 WPS Hide Login: by WPServeur NicolasKulka wpformation – 1.9.8

Inactive Plugins (18)

Akismet Anti-Spam: Spam Protection: by Automattic - Anti Spam Team – 5.1 All-in-One WP Migration: by ServMask – 7.73 Breeze: by Cloudways – 2.0.20 Easy WP SMTP: by Easy WP SMTP – 2.1.0 Folders: by Premio – 2.9.2 JSON Basic Authentication: by WordPress API Team – 0.1 Media Cleaner: by Jordy Meow – 6.6.3 Password Protected: by WPExperts – 2.6.2 Price Converter: by Selise – 1.0.0 Real Media Library (Free): by devowl.io – 4.18.37 Simple History: by Pär Thernström – 3.5.0 Sucuri Security - Auditing, Malware Scanner and Hardening: by Sucuri Inc. – 1.8.39 Wordfence Security: by Wordfence – 7.9.2 WP Crontrol: by John Blackbourn & crontributors – 1.15.2 WP Mail Logging: by WP Mail Logging Team – 1.11.0 WP Mail SMTP: by WPForms – 3.7.0 WP Migrate: by WP Engine – 2.6.1 Yoast SEO: by Team Yoast – 20.5

Dropin Plugins (1)

object-cache.php: Object Cache Pro (Drop-in)

Must Use Plugins (1)

Object Cache Pro (MU): by Rhubarb Group – 1.18.2

Settings

API Enabled: ✔ Force SSL: – Currency: CHF (CHF ) Currency Position: left_space Thousand Separator: ' Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: asset (asset) building (building) bundle (bundle) external (external) grouped (grouped) simple (simple) variable (variable)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5)

Connected to WooCommerce.com: – Enforce Approved Product Download Directories: – Order datastore: WC_Order_Data_Store_CPT

WC Pages

Shop base: #28 - /shop-old Cart: #633 - /cart Checkout: #635 - /checkout My account: #639 - /my-account Terms and conditions: #637 - /end-user-policy

Theme

Name: vrbn eshop Version: 1.0.0 Author URL: https://selise.ch Child Theme: ✔ Parent Theme Name: vrbn Parent Theme Version: 1.0.0 Parent Theme Author URL: https://selise.ch WooCommerce Support: ✔

Templates

Overrides: vrbn-eshop/woocommerce/cart/cart.php version 3.8.0 is out of date. The core version is 7.4.0 vrbn-eshop/woocommerce/checkout/cart-errors.php vrbn-eshop/woocommerce/checkout/form-billing.php vrbn-eshop/woocommerce/checkout/form-checkout.php vrbn-eshop/woocommerce/checkout/form-coupon.php version 3.4.4 is out of date. The core version is 7.0.1 vrbn-eshop/woocommerce/checkout/form-login.php vrbn-eshop/woocommerce/checkout/form-pay.php version 5.2.0 is out of date. The core version is 7.0.1 vrbn-eshop/woocommerce/checkout/form-shipping.php vrbn-eshop/woocommerce/checkout/order-receipt.php vrbn-eshop/woocommerce/checkout/payment-method.php vrbn-eshop/woocommerce/checkout/payment.php version 3.5.3 is out of date. The core version is 7.0.1 vrbn-eshop/woocommerce/checkout/review-order.php vrbn-eshop/woocommerce/checkout/terms.php vrbn-eshop/woocommerce/checkout/thankyou.php vrbn-eshop/woocommerce/emails/admin-cancelled-order.php vrbn-eshop/woocommerce/emails/admin-failed-order.php vrbn-eshop/woocommerce/emails/admin-new-order.php vrbn-eshop/woocommerce/emails/customer-completed-order.php vrbn-eshop/woocommerce/emails/customer-invoice.php vrbn-eshop/woocommerce/emails/customer-new-account.php vrbn-eshop/woocommerce/emails/customer-note.php vrbn-eshop/woocommerce/emails/customer-on-hold-order.php version 3.7.0 is out of date. The core version is 7.3.0 vrbn-eshop/woocommerce/emails/customer-processing-order.php vrbn-eshop/woocommerce/emails/customer-refunded-order.php vrbn-eshop/woocommerce/emails/customer-reset-password.php vrbn-eshop/woocommerce/emails/email-addresses.php vrbn-eshop/woocommerce/emails/email-customer-details.php vrbn-eshop/woocommerce/emails/email-downloads.php vrbn-eshop/woocommerce/emails/email-footer.php version 3.7.0 is out of date. The core version is 7.4.0 vrbn-eshop/woocommerce/emails/email-header.php version 4.0.0 is out of date. The core version is 7.4.0 vrbn-eshop/woocommerce/emails/email-mobile-messaging.php vrbn-eshop/woocommerce/emails/email-order-details.php vrbn-eshop/woocommerce/emails/email-order-items.php vrbn-eshop/woocommerce/emails/email-styles.php version 4.0.0 is out of date. The core version is 7.4.0 vrbn-eshop/woocommerce/emails/plain/admin-cancelled-order.php vrbn-eshop/woocommerce/emails/plain/admin-failed-order.php vrbn-eshop/woocommerce/emails/plain/admin-new-order.php vrbn-eshop/woocommerce/emails/plain/customer-completed-order.php vrbn-eshop/woocommerce/emails/plain/customer-invoice.php vrbn-eshop/woocommerce/emails/plain/customer-new-account.php vrbn-eshop/woocommerce/emails/plain/customer-note.php vrbn-eshop/woocommerce/emails/plain/customer-on-hold-order.php version 3.7.0 is out of date. The core version is 7.3.0 vrbn-eshop/woocommerce/emails/plain/customer-processing-order.php vrbn-eshop/woocommerce/emails/plain/customer-refunded-order.php vrbn-eshop/woocommerce/emails/plain/customer-reset-password.php vrbn-eshop/woocommerce/emails/plain/email-addresses.php vrbn-eshop/woocommerce/emails/plain/email-customer-details.php vrbn-eshop/woocommerce/emails/plain/email-downloads.php vrbn-eshop/woocommerce/emails/plain/email-order-details.php vrbn-eshop/woocommerce/emails/plain/email-order-items.php vrbn-eshop/woocommerce/myaccount/dashboard.php vrbn-eshop/woocommerce/myaccount/form-add-payment-method.php vrbn-eshop/woocommerce/myaccount/form-edit-account.php version 3.5.0 is out of date. The core version is 7.0.1 vrbn-eshop/woocommerce/myaccount/form-login.php version 6.0.0 is out of date. The core version is 7.0.1 vrbn-eshop/woocommerce/myaccount/form-lost-password.php version 3.5.2 is out of date. The core version is 7.0.1 vrbn-eshop/woocommerce/myaccount/form-reset-password.php version 3.5.5 is out of date. The core version is 7.0.1 vrbn-eshop/woocommerce/myaccount/lost-password-confirmation.php vrbn-eshop/woocommerce/myaccount/my-account.php vrbn-eshop/woocommerce/myaccount/navigation.php vrbn-eshop/woocommerce/myaccount/orders.php version - is out of date. The core version is 7.0.1 vrbn-eshop/woocommerce/myaccount/payment-methods.php vrbn-eshop/woocommerce/order/order-details.php vrbn-eshop/woocommerce/single-product/product-image.php vrbn-eshop/woocommerce/single-product/title.php

Outdated Templates: ❌

                    Learn how to update

Admin

Enabled Features: activity-panels analytics coupons customer-effort-score-tracks import-products-task experimental-fashion-sample-products shipping-smart-defaults shipping-setting-tour homescreen marketing multichannel-marketing mobile-app-banner navigation new-product-management-experience onboarding onboarding-tasks remote-inbox-notifications remote-free-extensions payment-gateway-suggestions shipping-label-banner subscriptions store-alerts transient-notices woo-mobile-welcome wc-pay-promotion wc-pay-welcome-page

Disabled Features: minified-js product-variation-management settings

Daily Cron: ✔ Next scheduled: 2023-05-11 05:33:04 +02:00 Options: ✔ Notes: 83 Onboarding: completed

Action Scheduler

Complete: 6,802 Oldest: 2023-04-11 07:30:14 +0200 Newest: 2023-05-10 14:37:56 +0200

Failed: 5 Oldest: 2023-02-19 05:31:06 +0100 Newest: 2023-03-28 09:09:40 +0200

Pending: 1 Oldest: 2023-05-11 11:01:54 +0200 Newest: 2023-05-11 11:01:54 +0200

Status report information

Generated at: 2023-05-10 20:12:02 +02:00 `

Isolating the problem

github-actions[bot] commented 1 year ago

Hi @sudipto-me,

Thank you for opening the issue! It requires further feedback from the WooCommerce Core team.

We are adding the needs developer feedback label to this issue so that the Core team could take a look.

Please note it may take a few days for them to get to this issue. Thank you for your patience.