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

order-attribution.min.js is throwing an error causing the rest of my JS to break #44159

Closed
4 of 5 tasks
JakobJR opened this issue Jan 29, 2024 · 12 comments
Closed
4 of 5 tasks
Assignees
Labels
focus: classic front end Issues related to the classic front end. focus: order attribution Issues related to the order attribution feature team: Ventures type: community contribution type: enhancement The issue is a request for an enhancement.

Comments

@JakobJR
Copy link

JakobJR commented Jan 29, 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

The file order-attribution.min.js throws an error.

Expected behavior

There should be no error.

Actual behavior

The file order-attribution.min.js throws an error causing the rest of my JS to be blocked.

I have not changed my checkout flow or code in more than a year.

Steps to reproduce

I'm not sure, but here is the error:
image

WordPress Environment

`

WordPress Environment

WordPress address (URL): https://mohdestudio.dk
Site address (URL): https://mohdestudio.dk
WC Version: 8.5.2
REST API Version: ✔ 8.5.2
WC Blocks Version: ✔ 11.8.0-dev
Action Scheduler Version: ✔ 3.7.1
Log Directory Writable: ✔
WP Version: 6.4.2
WP Multisite: –
WP Memory Limit: 2 GB
WP Debug Mode: –
WP Cron: ✔
Language: da_DK
External object cache: –

Server Environment

Server Info: Apache
PHP Version: 7.4.33
PHP Post Max Size: 1 GB
PHP Time Limit: 300
PHP Max Input Vars: 5000
cURL Version: 7.29.0
NSS/3.90

SUHOSIN Installed: –
MySQL Version: 8.0.35-27
Max Upload Size: 1 GB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

Database

WC Database Version: 8.5.2
WC Database Prefix: wp_
Total databasestørrelse: 40.48MB
Database datastørrelse: 31.36MB
Database indexstørrelse: 9.12MB
wp_woocommerce_sessions: Data: 1.02MB + Index: 0.05MB + 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.05MB + 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.22MB + Index: 0.22MB + 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.17MB + Index: 0.14MB + Engine InnoDB
wp_aws_cache: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_aws_index: Data: 2.52MB + Index: 2.03MB + Engine InnoDB
wp_berocket_termmeta: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_cli_cookie_scan: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_cli_cookie_scan_categories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_cli_cookie_scan_cookies: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_cli_cookie_scan_url: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_cli_scripts: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_comments: Data: 0.16MB + Index: 0.09MB + Engine InnoDB
wp_duplicator_packages: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_jetpack_sync_queue: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailchimp_carts: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_mailchimp_jobs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_options: Data: 5.19MB + Index: 0.30MB + Engine InnoDB
wp_postmeta: Data: 7.52MB + Index: 4.03MB + Engine InnoDB
wp_posts: Data: 0.17MB + 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.03MB + Index: 0.03MB + Engine InnoDB
wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_admin_note_actions: Data: 0.06MB + 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.06MB + Index: 0.05MB + 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
wp_wcpdf_invoice_number: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wdr_order_discounts: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wdr_order_item_discounts: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wdr_rules: Data: 0.02MB + Index: 0.00MB + 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.48MB + 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: 3.52MB + Index: 0.00MB + Engine InnoDB
wp_wfhits: Data: 0.06MB + Index: 0.05MB + Engine InnoDB
wp_wfhoover: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wfissues: Data: 0.05MB + Index: 0.06MB + Engine InnoDB
wp_wfknownfilelist: Data: 3.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.08MB + Index: 0.03MB + Engine InnoDB
wp_wfls_2fa_secrets: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wfls_role_counts: Data: 0.00MB + Index: 0.00MB + Engine MEMORY
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_wfsecurityevents: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wfsnipcache: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wfstatus: Data: 0.14MB + Index: 0.09MB + Engine InnoDB
wp_wftrafficrates: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wfwaffailures: 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: 4.52MB + Index: 0.00MB + Engine InnoDB
wp_yoast_indexable: Data: 0.23MB + Index: 0.09MB + Engine InnoDB
wp_yoast_indexable_hierarchy: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_yoast_migrations: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_yoast_primary_term: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_yoast_seo_links: Data: 0.05MB + Index: 0.03MB + Engine InnoDB

Post Type Counts

acf-field: 30
acf-field-group: 6
attachment: 1183
br_filters_group: 1
br_product_filter: 2
cookielawinfo: 6
nav_menu_item: 64
page: 8
post: 1
product: 269
product_variation: 1089
revision: 245
shop_coupon: 11
shop_order: 115
shop_order_refund: 6
wp_global_styles: 2

Security

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

Active Plugins (21)

Advanced Custom Fields PRO: af Delicious Brains – 5.12.2
Advanced Woo Search: af ILLID – 2.98
CookieYes | GDPR Cookie Consent: af CookieYes – 3.1.8
Duplicator: af Duplicator – 1.5.8
Facebook til WooCommerce: af Facebook – 3.1.9
Google Analytics for WordPress by MonsterInsights: af MonsterInsights – 8.23.1
Jetpack: af Automattic – 13.0
Mailchimp for WooCommerce: af Mailchimp – 3.6
Max Mega Menu: af megamenu.com – 3.3
Shipmondo til WooCommerce: af Shipmondo – 4.2.0
Regenerere miniaturebilleder: af Alex Mills (Viper007Bond) – 3.1.6
Variation Swatches for WooCommerce: af AovUp – 2.2.1
Preview E-mails for WooCommerce: af Digamber Pradhan – 2.2.1
Advanced AJAX Product Filters for WooCommerce: af BeRocket – 1.6.4.6
PDF Invoices & Packing Slips for WooCommerce: af WP Overnight – 3.7.7
WooCommerce QuickPay: af Perfect Solution – 7.0.4
WooCommerce: af Automattic – 8.5.2
Wordfence Security: af Wordfence – 7.11.1
Yoast SEO: af Team Yoast – 21.9.1
WP Mail Logging: af WP Mail Logging Team – 1.12.0
WP Mail SMTP: af WP Mail SMTP – 3.11.1

Inactive Plugins (0)

Settings

API Enabled: ✔
Force SSL: –
Currency: DKK (kr.)
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 Woo.com: –
Enforce Approved Product Download Directories: –
HPOS feature screen enabled: –
HPOS feature enabled: –
Order datastore: WC_Order_Data_Store_CPT
HPOS data sync enabled: –

WC Pages

Shop basisside: #6 - /shop/
Kurv: #7 - /kurv/
Checkout: #8 - /kasse/
Min konto: #9 - /min-konto/
Vilkår og betingelser: #260 - /handelsbetingelser/

Theme

Name: mohdestudio
Version: 1.0.0
Author URL: http://underscores.me/
Child Theme: ❌ – Hvis du redigerer WooCommerce i et hovedtema
som du ikke selv har udviklet
anbefaler vi
at du anvender et undertema (child theme). Se: Hvordan du opretter et undertema

WooCommerce Support: ✔

Templates

Overrides: mohdestudio/woocommerce/archive-product.php
mohdestudio/woocommerce/checkout/form-checkout.php
mohdestudio/woocommerce/checkout/form-coupon.php version 3.4.4 er udgået. Kerneversionen er 7.0.1
mohdestudio/woocommerce/checkout/thankyou.php version 3.7.0 er udgået. Kerneversionen er 8.1.0
mohdestudio/woocommerce/content-single-product.php
mohdestudio/woocommerce/loop/pagination.php
mohdestudio/woocommerce/single-product/product-image.php version 3.5.1 er udgået. Kerneversionen er 7.8.0

Outdated Templates: ❌

					Lær hvordan man opdaterer

Admin

Enabled Features: activity-panels
analytics
product-block-editor
coupons
core-profiler
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
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: customize-store
minified-js
new-product-management-experience
product-linked
settings
async-product-editor-category-field

Daily Cron: ✔ Next scheduled: 2024-01-30 19:07:26 +01:00
Options: ✔
Notes: 173
Onboarding: completed

Action Scheduler

Gennemført: 1.125
Oldest: 2023-12-29 20:46:08 +0100
Newest: 2024-01-29 19:59:41 +0100

Mislykket: 18
Oldest: 2022-11-06 18:19:49 +0100
Newest: 2023-06-01 09:09:43 +0200

Igangværende: 4
Oldest: 2024-01-30 01:49:41 +0100
Newest: 2024-02-05 13:54:43 +0100

Status report information

Generated at: 2024-01-29 20:15:12 +01: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.
@jonathansadowski
Copy link
Contributor

Hi @JakobJR,

Thanks for the report. I see that you're using a theme other than the default WordPress theme or Storefront. Can you confirm that you still see this issue with a default theme and/or storefront?

@jonathansadowski jonathansadowski added the needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. label Jan 29, 2024
@JakobJR
Copy link
Author

JakobJR commented Jan 29, 2024

@jonathansadowski

I can confirm there is no error when using a default theme, but I have never had any problems developing custom themes using WooCommerce. What should be the solution for me in this instance?

@github-actions github-actions bot added needs: triage feedback Issues for which we requested feedback from the author and received it. and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Jan 29, 2024
@JakobJR
Copy link
Author

JakobJR commented Jan 29, 2024

So I found out in my case, that not rendering the shipping fields (by removing do_action( 'woocommerce_checkout_shipping' );) causes the above error to be thrown.

Maybe we can check if they exist to avoid that error?

@RistoNiinemets
Copy link
Contributor

Order attribution fields are shown indeed via woocommerce_after_order_notes action (also woocommerce_register_form) and this one is shown in form-shipping.php template. I had to move the action outside of the template for same reason - shipping fields are not shown, at least on initial checkout load, when attribution fields are filled.

It'd be great if there was a

  • jQuery or JS document event to trigger attribution fields filling (setFields function in order-attribution.js)
  • possibility to change where attribution fields are rendered. Currently they are added via anonymous PHP function (that calls private method source_form_fields() in OrderAttributionController.php) and therefore it's not possible to remove and relocate.

@rrennick rrennick added type: enhancement The issue is a request for an enhancement. focus: checkout Issues related to checkout page. focus: classic front end Issues related to the classic front end. team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues focus: order attribution Issues related to the order attribution feature and removed needs: triage feedback Issues for which we requested feedback from the author and received it. focus: checkout Issues related to checkout page. labels Feb 1, 2024
@opr opr added team: Ventures and removed team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues labels Feb 2, 2024
@tomalec tomalec self-assigned this Feb 2, 2024
@tomalec
Copy link
Member

tomalec commented Feb 2, 2024

Thank you @JakobJR for reporting and investigating!

I already have a fix in mind, as I was planning to clean up a code a bit to make it bulletproof for bugs similar to this one.

From what you've reported:

So the quick fix would be just to add .length to the check, and we should be safe from the error.


However, I do see few more things to improve:

  1. As @RistoNiinemets mentioned, we use an anonymous function. We could make a public one, to allow custom themes, to add those fields when needed.
  2. We use woocommerce_after_order_notes ⊂ woocommerce_checkout_shipping, whereas the order attribution has nothing to do with shipping. I'd change it to render inputs on woocommerce_checkout_after_customer_details.
  3. If for some reason the page contains only a few <input name="wc_order_attribution_foo/>, but misses some other, <input name="wc_order_attribution_bar"/>, the current check would pass, but the rest would either crash, or go unnoticed. That could happen if somebody fiddled with the serverside code that renders the inputs, changed the fields list dynamically at runtime, or manipulated the DOM on the browser-side.
  4. The current code supports only one form at a time. This means that if somebody creates a template that renders many checkout and register forms on the same page, order attribution data will be added only to the first one. Which will go silently, unnoticed (at least not crashing the page), but would lose valuable data.

I'll create two PRs,

@tomalec
Copy link
Member

tomalec commented Feb 2, 2024

hm... wait

but the check is buggy, as $=document.querySelectorAll returns a NodeList which is always truthy, even if empty.

We use $=document.querySelector, which returns null. So the check is kinda correct.

So, if you see this error, it means you have some input[name^="wc_order_attribution"] on the page, but some specific fields are missing. Then, just gracefully checking for fields' existence to ignore the error may hide some other underlying problem!

@JakobJR
Could you please share the results of the following, for the page that throws the error?

  • document.querySelectorAll( `input[name^="${wc_order_attribution.params.prefix}"]` )
  • [...document.querySelectorAll( `input[name]` )].map((e)=>e.name)
  • wc_order_attribution.fields

tomalec added a commit that referenced this issue Feb 2, 2024
tomalec added a commit that referenced this issue Feb 2, 2024
in case the checkout form does not contain `woocommerce_checkout_shipping`, `woocommerce_after_order_notes`.

Addresses part of #44159
tomalec added a commit that referenced this issue Feb 2, 2024
to move DOM manipulations  to JS only.
To support multiple checkout & register forms on the same page.

Addresses #44159
tomalec added a commit that referenced this issue Feb 2, 2024
to move DOM manipulations  to JS only.
To support multiple checkout & register forms on the same page.

Addresses #44159
tomalec added a commit that referenced this issue Feb 3, 2024
to move DOM manipulations  to JS only.
To support multiple checkout & register forms on the same page.

Addresses #44159
@tomalec
Copy link
Member

tomalec commented Feb 3, 2024

I wasn't able to reproduce your scenario, so I'd appreciate your feedback so I can identify all the problems involved.

I published two PRs, still as a draft. I'd like to make sure they really fix your case, do a bit more testing, and polish them out. But feel free to try them out.

  1. Improve rendering of Order Attribution inputs #44333 - a minimalistic approach just to fix the problems you faced.
  2. Move rendering of Order Attribution inputs fully to JS #44335 - a bit bigger take, to cover also some hypothetical problems. I guess this may solve your issue to the fullest. Plus, IMO it makes further extending and debugging easier. Make PHP render <wc-order-attribution-input> in any form, and it will include the needed data. Inspect the wc-order-attribution-input element to debug. document.querySelector('wc-order-attribution-input').values = {...} to hack ;)

@RistoNiinemets
Copy link
Contributor

RistoNiinemets commented Feb 5, 2024

In case that attribution fields are not being rendered on checkout (for example action removed)

  • document.querySelectorAll( input[name^="${wc_order_attribution.params.prefix}"] ): NodeList [] length 0
  • [...document.querySelectorAll( input[name] )].map((e)=>e.name): https://share.konekt.ee/i/hiOJZ3
  • wc_order_attribution.fields: undefined

PR #44333 easily fixes the initial problem, which is great. Also adds possibility for custom checkout flows to output the input fields where necessary.

PR #44335 is indeed a bigger take. However, this one seems to eliminate issue where there could be registration form somewhere in checkout aswell (some slide-in form or what ever) and then renders all the values where is outputted, eliminates issue where values are not being filled because of multiple forms/inputs.

I quickly copied some code parts from your PRs to test out, but ran into issue where wc_order_attribution.fields was an array with numerated keys, so in JS this._fieldNames = Object.keys( wc_order_attribution.fields ); resulted in numerated array.

Maybe <wc-order-attribution-inputs>? 😄

@tomalec
Copy link
Member

tomalec commented Feb 5, 2024

Thank you for the quick answer.
I am happy to see that my PRs help (I'll continue to polish them)

However, I'm afraid there still may be something else contributing to the problem on you env:

  • wc_order_attribution.fields: undefined
  • wc_order_attribution.fields was an array with numerated keys

Suggests to me that something odd is happening. Wherever the order-attribution.js is loaded the wc_order_attribution.fields should be set synchronously by blocking script.

Could you open the page's source and search for "attribution"?
The expected one should look like:

<script src="https://my-site.test/wp-content/plugins/woocommerce/assets/js/sourcebuster/sourcebuster.min.js?ver=8.7.0" id="sourcebuster-js-js"></script>
<script id="wc-order-attribution-js-extra">
var wc_order_attribution = {"params":{"lifetime":1.0e-5,"session":30,"ajaxurl":"https:\/\/my-site.test\/wp-admin\/admin-ajax.php","prefix":"wc_order_attribution_","allowTracking":true},"fields":{"source_type":"current.typ","referrer":"current_add.rf","utm_campaign":"current.cmp","utm_source":"current.src","utm_medium":"current.mdm","utm_content":"current.cnt","utm_id":"current.id","utm_term":"current.trm","session_entry":"current_add.ep","session_start_time":"current_add.fd","session_pages":"session.pgs","session_count":"udata.vst","user_agent":"udata.uag"}};
</script>
<script src="https://my-site.test/wp-content/plugins/woocommerce/assets/js/frontend/order-attribution.min.js?ver=8.7.0" id="wc-order-attribution-js"></script>

Object.keys( wc_order_attribution.fields ); should return
image

@tomalec
Copy link
Member

tomalec commented Feb 5, 2024

Maybe <wc-order-attribution-inputs>? 😄

Do you mean to rename the element's name to plural with "s" at the end?
I answered in the PR thread

@RistoNiinemets
Copy link
Contributor

RistoNiinemets commented Feb 5, 2024

Okay so the issue actually is that I am using latest release (8.5.2) and you're working with trunk version :) In latest release, "fields" were not set with wp_localize_script and therefore the misunderstanding.

Looks good!

@tomalec
Copy link
Member

tomalec commented Feb 6, 2024

Ah! Thanks for checking! So it was #41690 that was improving the crashing error :)

tomalec added a commit that referenced this issue Feb 21, 2024
- Expose public method to render OA input fields 
- Render OA inputs on `woocommerce_checkout_after_customer_details` 
   in case the checkout form does not contain `woocommerce_checkout_shipping`, `woocommerce_after_order_notes`.

Addresses part of #44159

Co-authored-by: Justin Palmer <228780+layoutd@users.noreply.github.com>
Co-authored-by: github-actions <github-actions@github.com>
Konamiman pushed a commit that referenced this issue Feb 22, 2024
- Expose public method to render OA input fields 
- Render OA inputs on `woocommerce_checkout_after_customer_details` 
   in case the checkout form does not contain `woocommerce_checkout_shipping`, `woocommerce_after_order_notes`.

Addresses part of #44159

Co-authored-by: Justin Palmer <228780+layoutd@users.noreply.github.com>
Co-authored-by: github-actions <github-actions@github.com>
@layoutd layoutd closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: classic front end Issues related to the classic front end. focus: order attribution Issues related to the order attribution feature team: Ventures type: community contribution type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

No branches or pull requests

7 participants