Skip to content
Advertisement

Display shipping methods to frontend as in the admin panel?

In WooCommerce, I’m doing the form of adding / changing product (at the front-end). I need to display the fields for changing the cost of delivery of the installed methods as in the admin panel.

How can I do it?

Here is my actual code:

JavaScript

Advertisement

Answer

As Shipping Methods are connected to a Shipping Zone, WooCommerce need to know which is the customer shipping zone. So your script will not work in a correct way until you get that information.

To get that information, customer needs to logged in or if is not logged in it should need to add a product in cart…

Now the correct code to make your script working is:

JavaScript

Tested and works (only when the customer shipping zone is defined)


Now if you want to get everything like in shipping backend settings, you will need to:

  1. Get the shipping zones
  2. For each shipping zone you will get the available Shipping methods
  3. For each shipping method you can have shipping classes rates

So this is quite much more complicated…


Here is the way to start, but I didn’t find the way to get/set cost as it’s different for each shipping method type…

JavaScript

The class that make the Shipping cost is WC_Shipping_Rate


Other related recent answer: Display shipping cost on product page – WooCommerce

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement