0

I'm using multi-step checkout process and I'm trying to display only the shipping method options on the second step. ( image ) https://i.stack.imgur.com/kGO8D.jpg

By the default the shipping methods are displayed in the checkout page which I'll split into 3 parts:

  1. Billing and Shipping contact details
  2. Shipping Methods
  3. Order review and 'complete checkout' process

My current code returns an empty array and not sure what I'm doing wrong.

add_action( 'woocommerce_review_order_after_shipping', 'woo_shipping_test' );
function woo_shipping_test() {
  $available_shipping = WC()->shipping->get_shipping_methods();
  var_dump($available_shipping);
}
Malenko123
  • 11
  • 4
  • Do you have shipping zones set up? – Dajer May 16 '19 at 15:00
  • Of course, you can see it on the image link. They're already setup, I just need to move that in a separate section - Step 2. – Malenko123 May 16 '19 at 15:02
  • I would check whether this hook (`woocommerce_review_order_after_shipping`) is actually called on you shipping method page, or not. – Dajer May 16 '19 at 15:11
  • @Dajer Thank you for that comment, I was looking for that code at review-order.php and did find this lines of code: That's one way to call the shipping methods but now something weird is happening, when I check any of those shipping methods ( radio buttons ), after a few seconds the radio buttons get unchecked? Any idea why's that happening? – Malenko123 May 20 '19 at 07:33
  • Well, shipping is a complex part of Woocommerce. Basically the shipping price is calculated from the shipping location and the selected method, so if you change any of these, it re-renders the whole review order part with an AJAX request. I think this might be related to your issue, but check the network tab in the inspector to make sure. ;) – Dajer May 20 '19 at 09:44

1 Answers1

1

@Dajer

Thanks buddy. I solved my problem - just commenting here just in case someone needs it ( even if this is very much adjusted to the client needs ).

I've added these lines of code in Step 2 of the checkout process. Although if you click on any of the radio buttons, it gets unchecked in a few seconds but it's still working and processing the selected shipping method as it should. As for ( checked, unchecked ) bug, I applied a bit of CSS as some sort of workaround.

I guess maybe it's not the best solution but that's good enough for now.

<?php do_action( 'woocommerce_review_order_before_shipping' ); ?>

<?php WC()->cart->calculate_totals(); ?>

<?php wc_cart_totals_shipping_html(); ?>

<?php do_action( 'woocommerce_review_order_after_shipping' ); ?>
Malenko123
  • 11
  • 4
  • It works perfectly but there is issue. When I changed country then new shipping method not change. How we can do that one? – Gaurav Sharna Apr 08 '22 at 08:20