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:
<form>
<!-- Various input fields -->
<?php foreach ($shipping_methods as $method) { ?>
<lebel>
<h3><?php echo $method ?></h3>
<input type="number" value="<?php //hook for input - output to make changes of shipping price of this method??Which one ?>">
</lebel>
<?php } ?>
<input type="submit" value="<?php echo $edit_action ? "Save" : "Add"; ?> Product">
</form>
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.
Now the correct code to make your script working is:
Tested and works (only when the customer shipping zone is defined)…
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…
The class that make the Shipping cost is
WC_Shipping_Rate
Other related recent answer: Display shipping cost on product page - WooCommerce