• Resolved arbremojo

    (@arbremojo)


    Hi,

    I would like to get the shipping cost before payment, but I can’t as the user choose its delivery options only on checkout and not in the cart page. So I cannot get this data from WC->cart, neither of $order because the order hasn’t been created yet.

    If it is possible, I would like to display this data with the hook woocommerce_review_order_before_payment because this is where I want my data to be displayed.

    Any help will be appreciated!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi there @arbremojo ??

    I would like to get the shipping cost before payment, but I can’t as the user choose its delivery options only on checkout and not in the cart page. So I cannot get this data from WC->cart, neither of $order because the order hasn’t been created yet.

    Thanks for reaching out! From what I understand, you would like to enable shipping calculations on the cart page.

    Fortunately, this is possible via the shipping settings, as the documentation details here.

    Furthermore, the rest of the related documentation on shipping can be found here.

    I hope that helps!

    Thread Starter arbremojo

    (@arbremojo)

    No no, I just would like to display shipping cost at the top of payment methods table on the checkout page. But it need to be an AJAX block I think, because this value is updated depending on the delivery option the user choose on the same page.

    Hello,

    I was testing on my site which has WooCommerce, and Storefront theme, my cart is being updated depending on the shipping as well as checkout page, may I ask, is not the same on your site?

    This is on the cart page:

    Link to image: https://gifyu.com/image/S9D3q

    And this is at checkout:

    Link to image: https://gifyu.com/image/S9D3d

    If you are referring to Rest API, you can check this work-around:
    Get cost value of chosen shipping method at checkout of Woocommerce.

    Does that work for you? Let us know if there are any questions.

    • This reply was modified 2 years, 5 months ago by Igor H.
    Thread Starter arbremojo

    (@arbremojo)

    Hi,

    Yes I’m more referring to Rest API actually.

    Here is the function I made:

    function order_review_checkout_payment_step()
    {
        $cart = WC()->cart;
        $total = $cart->total;
    
        echo wc_price($total);
    }
    add_action('woocommerce_review_order_before_submit', 'order_review_checkout_payment_step', 1);

    It’s kinda the same thing as the stackoverflow topic you sent me. Actually, the total value isn’t updated because the woocommerce_review_order_before_submit hook doesn’t refresh the values. However, with the woocommerce_review_order_before_submit hook, it works. But I want to display my value above the payment table.

    Hi,

    Please note, custom code is not supported on our forum.

    However, may I ask if ou temporarily switch your theme to Storefront and disable all plugins except WooCommerce does the code work as expected?

    There are cases when it is not possible to make changes on the live site, for that reason, we recommend WP Staging for quickly spinning up a new test site, that way you can check on a staging environment.

    Let us know if that makes a difference.

    Thread Starter arbremojo

    (@arbremojo)

    Hi,

    I’m talking about custom code, and apparently you don”t support it, so I think you can close the topic then…

    Regards,

    Clara.

    Saif

    (@babylon1999)

    Hello @arbremojo,

    Unfortunately, debugging code is not within our support policy.

    I will go ahead and mark the thread as solved as you requested. I can also recommend visiting the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to get shipping cost before payment form?’ is closed to new replies.