Support » Plugin: WebData Custom Shipping Methods for WooCommerce » Bug in the total cart price variable (leads to free shipping malfunction)

  • Resolved vlastimil001

    (@vlastimil001)


    Hi, I’m really surprised to find such a great plugin, thank you! During setting it up I’ve found out that the free shipping limit wasn’t working (shipping price was always 0). The problem lies in the wrong value of $cart_price. Preg_replace() in the plugin code (see below) always appends some additional digits to the end of the variable, so it outputs an extremely high number.

    EXAMPLE:
    Price received from WC get_cart_total(): “550 Kč” (Czech currency)
    $cart_price value after preg_replace: “55075269” (The additional digits “75269” are always the same – They correspond to the decimal values of unicode characters “K” and “č”.)

    PLUGIN CODE:
    $cart_price = preg_replace( '#[^\d.,]#', '', $woocommerce->cart->get_cart_total() );

    MY SOLUTION:
    I’ve replaced the code by another way of receiving the cart total (inspired by https://stackoverflow.com/questions/30063173/woocommerce-get-cart-total-as-number):

    if ( WC()->cart->prices_include_tax ) {
        $cart_price = $woocommerce->cart->get_cart_contents_total() + $woocommerce->cart->get_cart_contents_tax();
    } else {
        $cart_price = $woocommerce->cart->get_cart_contents_total();
    }
    • This topic was modified 7 months ago by vlastimil001.
    • This topic was modified 7 months ago by vlastimil001.
    • This topic was modified 7 months ago by vlastimil001. Reason: Added the explanation for appended digits
Viewing 1 replies (of 1 total)
  • Plugin Author webdata

    (@webdata)

    Hi,

    Thanks for the report! I will investigate this further and release then a fix.

    Kim

Viewing 1 replies (of 1 total)
  • The topic ‘Bug in the total cart price variable (leads to free shipping malfunction)’ is closed to new replies.