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

Fatal error when try to create an order using API REST where include a coupon code with email restrictions. #47224

Open
5 tasks done
crodriguezbrito opened this issue May 7, 2024 · 0 comments

Comments

@crodriguezbrito
Copy link

crodriguezbrito commented May 7, 2024

Prerequisites

  • I have carried out troubleshooting steps and I believe I have found a bug.
  • I have searched for similar bugs in both open and closed issues and cannot find a duplicate.

Describe the bug

A fatal error is generated when you try to create an order using the WooCommerce API Rest and this order include a coupon code with "Allowed email" restrictions.

Expected behavior

The expected behaviour should an order created with the coupon code associated.

Actual behavior

The following fatal error appear:

PHP Fatal error: Uncaught Error: Call to a member function is_coupon_emails_allowed() on null in /Users/carlosrodriguez/Local Sites/debug/app/public/wp-content/plugins/woocommerce/includes/class-wc-discounts.php:979
Stack trace:
#0 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-content/plugins/woocommerce/includes/class-wc-discounts.php(1046): WC_Discounts->validate_coupon_allowed_emails(Object(WC_Coupon))
#1 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-orders-controller.php(73): WC_Discounts->is_coupon_valid(Object(WC_Coupon))
#2 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-orders-controller.php(218): WC_REST_Orders_Controller->calculate_coupons(Object(WP_REST_Request), Object(WC_Order))
#3 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php(191): WC_REST_Orders_Controller->save_object(Object(WP_REST_Request), true)
#4 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/rest-api/class-wp-rest-server.php(1230): WC_REST_CRUD_Controller->create_item(Object(WP_REST_Request))
#5 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/rest-api/class-wp-rest-server.php(1063): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wc/v3/orders', Array, NULL)
#6 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/rest-api/class-wp-rest-server.php(439): WP_REST_Server->dispatch(Object(WP_REST_Request))
#7 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/rest-api.php(428): WP_REST_Server->serve_request('/wc/v3/orders')
#8 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/class-wp-hook.php(324): rest_api_loaded(Object(WP))
#9 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#10 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#11 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/class-wp.php(418): do_action_ref_array('parse_request', Array)
#12 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/class-wp.php(813): WP->parse_request('')
#13 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-includes/functions.php(1336): WP->main('')
#14 /Users/carlosrodriguez/Local Sites/debug/app/public/wp-blog-header.php(16): wp()
#15 /Users/carlosrodriguez/Local Sites/debug/app/public/index.php(17): require('/Users/carlosro...')
#16 {main}
thrown in /Users/carlosrodriguez/Local Sites/debug/app/public/wp-content/plugins/woocommerce/includes/class-wc-discounts.php on line 979
[07-May-2024 15:03:58 UTC] Array
(
[code] => internal_server_error
[message] =>

There has been a critical error on this website.

Learn more about troubleshooting WordPress.


[data] => Array
(
[status] => 500
)

[additional_errors] => Array
    (
    )

)

Steps to reproduce

1.- Create a coupon code and include a user email on "Allowed emails" field
2.- Create an order using the WooCommerce order endpoint and associate the order to the customer that you previously set in the "Allowed emails" field.
3.- You'll see the fatal error

WordPress Environment

`

WordPress Environment

WordPress address (URL): http://debug.local
Site address (URL): http://debug.local
WC Version: 8.8.3
REST API Version: ✔ 8.8.3
Action Scheduler Version: ✔ 3.7.4
Log Directory Writable: ✔
WP Version: 6.5.2
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: ✔
WP Cron: ✔
Language: en_US
External object cache: –

Server Environment

Server Info: nginx/1.16.0
PHP Version: 8.1.23
PHP Post Max Size: 1,000 MB
PHP Time Limit: 1200
PHP Max Input Vars: 4000
cURL Version: 8.1.2
(SecureTransport) LibreSSL/3.3.6

SUHOSIN Installed: –
MySQL Version: 8.0.16
Max Upload Size: 300 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

Database

WC Database Version: 8.8.3
WC Database Prefix: wp_
Total Database Size: 5.28MB
Database Data Size: 3.59MB
Database Index Size: 1.69MB
wp_woocommerce_sessions: Data: 0.02MB + 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: 0.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: 0.02MB + Index: 0.11MB + 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: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_comments: Data: 0.02MB + Index: 0.08MB + Engine InnoDB
wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_options: Data: 2.50MB + Index: 0.06MB + Engine InnoDB
wp_postmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_posts: Data: 0.06MB + Index: 0.06MB + 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_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_admin_note_actions: Data: 0.05MB + Index: 0.02MB + Engine InnoDB
wp_wc_admin_notes: Data: 0.06MB + Index: 0.00MB + 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_addresses: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_order_operational_data: 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_orders: Data: 0.02MB + Index: 0.11MB + Engine InnoDB
wp_wc_orders_meta: 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.02MB + 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

Post Type Counts

attachment: 1
page: 7
post: 2
product: 1
revision: 1
shop_coupon: 3
shop_order: 7
wp_font_face: 33
wp_font_family: 12

Security

Secure connection (HTTPS): ❌
Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates.
Hide errors from visitors: ✔

Active Plugins (1)

WooCommerce: by Automattic – 8.8.3

Inactive Plugins (0)

Settings

API Enabled: –
Force SSL: –
Currency: EUR (€)
Currency Position: right_space
Thousand Separator: .
Decimal Separator: ,
Number of Decimals: 2
Taxonomies: Product Types: 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: ✔
HPOS feature screen enabled: ✔
HPOS feature enabled: ✔
Order datastore: Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore
HPOS data sync enabled: ✔

Logging

Enabled: ✔
Handler: Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2
Retention period: 30 days
Level threshold: –
Log directory size: 6 KB

WC Pages

Shop base: #6 - /shop/
Cart: #7 - /cart/
Checkout: #8 - /checkout/
My account: #9 - /my-account/
Terms and conditions: ❌ Page not set

Theme

Name: Storefront
Version: 4.5.5
Author URL: https://woocommerce.com/
Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
WooCommerce Support: ✔

Templates

Overrides: –

Admin

Enabled Features: activity-panels
analytics
product-block-editor
coupons
core-profiler
customize-store
customer-effort-score-tracks
import-products-task
experimental-fashion-sample-products
shipping-smart-defaults
shipping-setting-tour
homescreen
marketing
mobile-app-banner
navigation
onboarding
onboarding-tasks
product-variation-management
product-virtual-downloadable
product-external-affiliate
product-grouped
product-linked
product-pre-publish-modal
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
new-product-management-experience
product-custom-fields
settings
async-product-editor-category-field
launch-your-store

Daily Cron: ✔ Next scheduled: 2024-05-08 14:26:54 +00:00
Options: ✔
Notes: 65
Onboarding: completed

Action Scheduler

Complete: 18
Oldest: 2024-05-07 14:26:55 +0000
Newest: 2024-05-07 14:49:34 +0000

Failed: 1
Oldest: 2024-05-07 14:28:23 +0000
Newest: 2024-05-07 14:28:23 +0000

Pending: 3
Oldest: 2024-05-07 15:48:55 +0000
Newest: 2024-05-08 14:28:11 +0000

Status report information

Generated at: 2024-05-07 15:04:11 +00:00
`

Isolating the problem

  • I have deactivated other plugins and confirmed this bug occurs when only WooCommerce plugin is active.
  • This bug happens with a default WordPress theme active, or Storefront.
  • I can reproduce this bug consistently using the steps above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant