• Resolved olppa

    (@olppa)


    I’m using newest versions of all related plugins (WC, Klarna, Paytrail, WT Smart coupons).
    I get an error in console and wc dismissable notice “Parametri tai parametrejä puuttuu: billing_address” when changing payment method in block checkout.

    Error message from devtools:
    wt-smart-coupon-public.js?ver=2.2.3:146 Uncaught TypeError: Cannot read properties of undefined (reading ‘split’) at HTMLInputElement. (wt-smart-coupon-public.js?ver=2.2.3:146:50) at ce.each (jquery.min.js?ver=3.7.1:2:3129) at e..each (jquery.min.js?ver=3.7.1:2:1594) at wbte_set_block_checkout_values (wt-smart-coupon-public.js?ver=2.2.3:145:90) at HTMLInputElement. (wt-smart-coupon-public.js?ver=2.2.3:99:17) at HTMLDocument.dispatch (jquery.min.js?ver=3.7.1:2:40035) at v.handle (jquery.min.js?ver=3.7.1:2:38006) (anonymous) @ wt-smart-coupon-public.js?ver=2.2.3:146 each @ jquery.min.js?ver=3.7.1:2 each @ jquery.min.js?ver=3.7.1:2 wbte_set_block_checkout_values @ wt-smart-coupon-public.js?ver=2.2.3:145 (anonymous) @ wt-smart-coupon-public.js?ver=2.2.3:99 dispatch @ jquery.min.js?ver=3.7.1:2 v.handle @ jquery.min.js?ver=3.7.1:2Understand this error api-fetch.min.js?ver=3623a576c78df404ff20:2 POST https://linssikauppa.fi/wp-json/wc/store/v1/checkout?__experimental_calc_totals=true&lang=fi&_locale=site 400 (Bad Request)

    From chatgpt:
    Ask WebToffee to add null-checks before any .split() calls in wt-smart-coupon-public.js (around the code that posts to set_block_checkout_values). Provide your exact stack trace and mention WooCommerce Checkout Block + payment-method toggle.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter olppa

    (@olppa)

    Chatgpt suggested fix.
    In wt-smart-coupon-public.js

    Change this:
    $(‘.wc-block-components-shipping-rates-control input[type=”radio”]:checked’).each(function(){ let prefix = $(this).attr(‘name’).split(‘-‘).pop(); shipping_method[prefix] = $(this).val(); });

    To this:
    $(‘.wc-block-components-shipping-rates-control input[type=”radio”]:checked’).each(function(){
    const name = $(this).attr(‘name’) || ”;
    // Try bracket syntax first: shipping_method[0]
    const m = name.match(/[(\d+)]/);
    let prefix = m ? m[1] : (name.includes(‘-‘) ? name.split(‘-‘).pop() : ‘0’);

    const val = $(this).val();
    if (typeof val === ‘string’ && val.length) {
    shipping_method[prefix] = val;
    }
    });

    Handles both shipping_method[0] and shipping-method-0.
    
    Never calls .split() on undefined.
    
    Falls back to package index '0' if neither pattern is present.
    
    Skips empty/undefined values safely.
    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @olppa,

    Thank you for sharing the suggested fix and the detailed explanation. That’s very helpful.

    Let me check this further with our development team and we’ll provide you with an update once we’ve reviewed it on our side.

    Thread Starter olppa

    (@olppa)

    @webtoffeesupport Thank you for the quick reply.

    I would also like to raise another issue.

    Smart coupons reserves space for coupons by creating a wrapper div above the checkout form.
    The wrapper classes: wbte_sc_block_coupon_wrapper_div and wt_coupon_wrapper.
    I don’t use the feature to display coupons in the checkout but Smart Coupons reserves the space anyway and creates an unneccesary dom element and whitespace in the checkout.
    Can your developers also see about removing the wrapper divs?

    See image here: https://pasteboard.co/5L11zjLKhToB.png

    I would suggest making the “Display coupon in” setting a global setting.
    There would first be a global setting: “Enable coupons to display” and when selected the the option to display the coupon in myaccount/cart/checkout would appear in the indivual coupon settings.
    This would also reduce unneccessary database queries.

    • This reply was modified 8 months ago by olppa.
    • This reply was modified 8 months ago by olppa.
    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @olppa,

    Thank you once again for sharing this additional feedback and for illustrating it with a screenshot. That’s very helpful.

    We’ve noted both of your points:

    1. Adding null-checks around .split() in wt-smart-coupon-public.js to avoid errors in the block checkout.
    2. Improving the way coupon wrapper divs (wbte_sc_block_coupon_wrapper_div and wt_coupon_wrapper) are handled so that unnecessary elements/whitespace aren’t rendered when coupons aren’t displayed.

    We’ll review both with our development team, and we’ll keep you posted once we have an update.

    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @olppa,

    Thanks for waiting.

    Regarding the Block Checkout JS error, our team wasn’t able to replicate this on our side. Could you please confirm which payment method(s) you were using when the error appeared? That will help us reproduce it more accurately. You can securely share these details via this link.

    For the extra coupon wrapper div, we’ve addressed this and the fix will be included in the next official release of the plugin.

    If this is urgent for your store and you’d prefer not to wait for the release, please let us know.

    Thread Starter olppa

    (@olppa)

    Hi @webtoffeesupport ,

    We are using Klarna for WooCommerce and Paytrail for WooCommerce.

    I’ve disabled Smart Coupons for now and I’m still getting a 400 bad request error.
    The error might actually be caused by the Klarna plugin.

    I started a support topic with Klarna regarding the issue.
    You can find more information here:
    https://wordpress.org/support/topic/400-bad-request-error-when-changing-payment-method-in-block-checkout/#new-topic-0

    Plugins and themes we use.
    WC version: 10.1.2 (newest)
    Klarna for WooCommerce version: 4.2.0 (newest)
    Klarna Order Management for WooCommerce version: 1.9.9 (newest)
    Paytrail for WooCommerce version: 2.5.3 (newest)
    Blocksy theme and companion plugins (newest versions).

    • This reply was modified 7 months, 2 weeks ago by olppa.
    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @olppa,

    Thank you for sharing all this detailed information.

    We’ve noted the issues you raised:

    • One was related to the Smart Coupons code that updates the selected shipping method to the session. While we weren’t able to replicate the error on our side (even after testing with Paytrail for WooCommerce), we’ve made adjustments in the plugin code based on your error log.
    • The other was the unnecessary .wt_coupon_wrapper div being displayed — this has also been addressed.

    Both fixes have been implemented and will be included in the next release of the plugin.

    We also acknowledge your point regarding Klarna — since that’s outside the scope of our plugin, it’s great that you’ve already raised it with Klarna support.

    We appreciate your detailed feedback and will keep you updated once the changes are released.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Block checkout payment method change causes error’ is closed to new replies.