I want to add a custom field in Shipping Zone page under shipping method, it will be a text input, the user will able to add a custom message and I'll show that message in the front end.
I noticed it saves the data in wp_woocommerce_shipping_zone_methods
table which doesn't have any extra column to save the data; so I think I have to use my custom logic, but I don't know the name of the hook(s).
So my question is, is there is any hook which will help/allow me
TL;DR:
add_action('woocommerce_init', 'shipping_instance_form_fields_filters');
function shipping_instance_form_fields_filters()
{
$shipping_methods = WC()->shipping->get_shipping_methods();
foreach($shipping_methods as $shipping_method) {
add_filter('woocommerce_shipping_instance_form_fields_' . $shipping_method->id, 'shipping_instance_form_add_extra_fields');
}
}
function shipping_instance_form_add_extra_fields($settings)
{
$settings['shipping_extra_field'] = [
'title' => 'Shipping extra field',
'type' => 'text',
'placeholder' => 'shipping',
'description' => ''
];
return $settings;
}
Thanks @Wprog_dy for idea, but your code only adds field to the 'flat_rate' shipping method and your function is really weirdly complicated.
My example will add a custom field to all shipping methods
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With