[SUPPORT NOTICE] We will close from 27 April to 01 May to celebrate our Reunification Day and Labor Day!

Cart

Add a custom field to each shipping method settings in WooCommerce admin

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9916
    Participant

    How can I add comments to the delivery methods To WooCommerce admin shipping section in each shipping method?

    I use WoodMart theme and this is only for administrative use (only visible in the admin panel, no need to display it on the site).

    I tried this, but it didn’t work

    add_filter( 'woocommerce_shipping_instance_form_fields', 'add_shipping_comments', 10, 2 ); 
     
    function add_shipping_comments( $fields, $instance ) { 
        if ( current_user_can( 'manage_options' ) ) { 
            $fields['shipping_comment'] = array( 
                'title'       => __( 'Shipping Comment', 'woocommerce' ), 
                'type'        => 'textarea', 
                'description' => __( 'Enter any additional comments for this shipping method.', 'woocommerce' ), 
                'default'     => "", 
            ); 
        } 
        return $fields;
    }
    
    #9917
    loictheaztec
    Participant

    Use the following, to add a custom field in WooCommerce admin shipping, to each shipping methods setting fields:

    add_action('woocommerce_init', 'woocommerce_shipping_instances_form_fields_filters');
    function woocommerce_shipping_instances_form_fields_filters(){
        foreach( WC()->shipping->get_shipping_methods() as $shipping_method ) {
            add_filter('woocommerce_shipping_instance_form_fields_' . $shipping_method->id, 'shipping_methods_additional_custom_field');
        }
    }
    
    function shipping_methods_additional_custom_field( $settings ) {
        $settings['shipping_comment'] = array(
            'title'         => __('Shipping Comment', 'woocommerce'),
            'type'          => 'text', 
            'placeholder'   => __( 'Enter any additional comments for this shipping method.', 'woocommerce' ),
        );
        return $settings;
    } 
    

    Code goes in functions.php file of your child theme (or in a plugin). Tested and works.

    enter image description here

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.