Merge pull request #1655 from woocommerce/PCP-1971-product-page-pp-button-keep-loading-popup-wc-add-to-cart-params-is-not-defined-error-in-woo-commerce

Product page PP button keep loading popup - "wc_add_to_cart_params is not defined" error in WooCommerce (1971)
This commit is contained in:
Emili Castells 2023-09-07 09:39:43 +02:00 committed by GitHub
commit 957016d2a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,10 +2,19 @@ class CartHelper {
constructor(cartItemKeys = [])
{
this.endpoint = wc_cart_fragments_params.wc_ajax_url.toString().replace('%%endpoint%%', 'remove_from_cart');
this.cartItemKeys = cartItemKeys;
}
getEndpoint() {
let ajaxUrl = "/?wc-ajax=%%endpoint%%";
if ((typeof wc_cart_fragments_params !== 'undefined') && wc_cart_fragments_params.wc_ajax_url) {
ajaxUrl = wc_cart_fragments_params.wc_ajax_url;
}
return ajaxUrl.toString().replace('%%endpoint%%', 'remove_from_cart');
}
addFromPurchaseUnits(purchaseUnits) {
for (const purchaseUnit of purchaseUnits || []) {
for (const item of purchaseUnit.items || []) {
@ -46,7 +55,7 @@ class CartHelper {
continue;
}
fetch(this.endpoint, {
fetch(this.getEndpoint(), {
method: 'POST',
credentials: 'same-origin',
body: params