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 - avoid attributing AJAX-checkouts to Web Admin #44219
Order attribution - avoid attributing AJAX-checkouts to Web Admin #44219
Conversation
Test Results SummaryCommit SHA: a0354fb
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
Hi @budzanowski, 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: |
StackOverflow suggests that it is possible to check if we have the admin doing Ajax: https://wordpress.stackexchange.com/a/286299 Would this approach improve precision or this does not cover the scenarios that we want to target? |
That might be more precise, is it common for orders to be created via ajax in the admin panel? |
I added a more detailed check that will allow the possibility for Web Admin orders to be created via AJAX calls. |
I don't know, sorry :/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I made one more small change to clarify the logic, would you mind doing a quick sanity check, @budzanowski? |
@layoutd done. |
aabe50f
to
a0354fb
Compare
Changes proposed in this Pull Request:
This prevents orders created through AJAX checkout requests from getting an extra
source_type
meta value as "Web admin" incorrectly. Ref p1706574180153889-slack-C7U3Y3VMYHow to test the changes in this Pull Request:
Ensure that orders created in the Web Admin are still classified as Web Admin:
/wp-admin/post-new.php?post_type=shop_order
).Ensure that orders created via AJAX requests aren't classified as Web Admin
Configure the shop:
Add some products to the cart.
Go to the checkout page, confirm there's a
woocommerce-process-checkout-nonce
:Execute the following snippet in the browser dev console (it will attempt to build the URL automatically assuming
shop.dom/checkout/
is the URL; otherwise, set the URL manually):JavaScript block
```javascript var nonce_val = jQuery('#woocommerce-process-checkout-nonce').val(); var ajax_url =window.location.href .replace( '/checkout/', '/wp-admin/admin-ajax.php?action=woocommerce_checkout&woocommerce-process-checkout-nonce=' + nonce_val );jQuery.post(
ajax_url,
{
billing_first_name: "PR44219",
billing_last_name: "Test",
billing_company: "",
billing_country: "UA",
billing_address_1: "Test",
billing_address_2: "Test",
billing_city: "Test",
billing_state: "UA07",
billing_postcode: "44219",
billing_phone: "44219",
billing_email: "admin@example.com",
shipping_first_name: "PR44219",
shipping_last_name: "Test",
shipping_company: "",
shipping_country: "UA",
shipping_address_1: "Test",
shipping_address_2: "Test",
shipping_city: "Test",
shipping_state: "UA07",
shipping_postcode: "44219",
order_comments: "",
shipping_method: ["flat_rate:3"],
payment_method: "cod",
wc_order_attribution_source_type: 'utm',
wc_order_attribution_referrer: '(none)',
wc_order_attribution_utm_campaign: 'sale',
wc_order_attribution_utm_source: 'NEWSOURCE',
wc_order_attribution_utm_medium: 'social',
wc_order_attribution_utm_content: '(none)',
wc_order_attribution_utm_id: '20231121',
wc_order_attribution_utm_term: 'testing',
wc_order_attribution_session_entry: 'https://fakestore.com/shop',
wc_order_attribution_session_start_time: '2024-01-31 11:30:13',
wc_order_attribution_session_pages: '8',
wc_order_attribution_session_count: '2',
wc_order_attribution_user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ 120.0.0.0 Safari/537.36',
})
.done(function(data, textStatus, jqXHR) {
console.log('Status Code:', jqXHR.status);
console.log('Status Text:', jqXHR.statusText);
console.log('WooCommerce Response:', data.result);
if(data.order_id) {
console.log('WooCommerce Order ID:', data.order_id);
}
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.error('Status Code:', jqXHR.status);
console.error('Status Text:', jqXHR.statusText);
});
Confirm in the dev console that the console show
Status Code: 200
andStatus Text: success
.Note that without these changes, the "Origin" in the Orders Table will be Web Admin, and with it, it will show the Source:
(In the page edit form the correct Source value will always be displayed):
Ensure that regular orders are still attributed correctly
web.com/shop/?utm_source=GOODTEST&utm_medium=test&utm_campaign=pr-test
Changelog entry
Significance
Type
Message
Comment