vince
vince

Reputation: 172

how to add a section to the WooCommerce settings "Shipping" tab

The filter hook woocommerce_sections_shipping is not working to add a section tab to woocommerce shipping settings:

 if ( ! class_exists('WC_Shipping_Calculator')){
    class WC_Shipping_Calculator{
        public function __construct(){

            add_filter('woocommerce_get_settings_shipping', array( $this, 'add_settings_tab'), 100);
            //add_filter('woocommerce_settings_tabs_array', array( $this, 'add_settings_tab'), 100);
            //add_filter('woocommerce_sections_shipping_array', array( $this, 'add_settings_tab'), 100);
        }

        public function add_settings_tab($settings_tabs){
            $settings_tabs['shipping_calculator'] = __('Shipping Calculator', 'shipping-calculator');
            return $settings_tabs;

        }
    }
}

$GLOBAL['wc_shipping_calculator'] = new WC_Shipping_Calculator();

What is the filter that I can use to add a section tab to woocommerce shipping settings?

Upvotes: 4

Views: 1632

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253784

To add a custom additional tab to Woocommerce shipping settings, you will use:

if ( ! class_exists('WC_Shipping_Calc')){
    class WC_Shipping_Calc{
        public function __construct(){

            add_filter('woocommerce_get_sections_shipping', array( $this, 'add_shipping_settings_section_tab') );
        }

        public function add_shipping_settings_section_tab( $section ){
            $section['shipping_calc'] = __('Shipping Calculator', 'shipping-calculator');;

            return $section;
        }

    }
    $GLOBAL['wc_shipping_calc'] = new WC_Shipping_Calc();
}

Tested and works.

enter image description here

As there is a shipping calculator already in Woocommerce, to avoid problems, I have changed the class name

Upvotes: 6

Related Questions