0
votes

I'm overriding Woocommerce theme. And now I have to override customize panel. There is a few woocommerce default sections in Customize panel to change some Woocommerce data, labels etc. (such as image size, number of post per page, privacy text...). And I want to add my own customize panel fields to make some data in my child theme to be easy to change (they should be placed in the same control panel sections next to Woocommerce default fields).

There is Woocommerce/Includes/Customizer/*customizer files*. So I can simply override that files in Woocommerce folder but when Woocommerce will be updated I'll lose my changes.

So I need to add my customize fields (and I think the best way is write them somewhere in my child theme maybe in functions.php but I didn't manage to do it yet) in the same Woocommerce control panel tabs and sections. (For example in section Product Catalog (that's woocommerce default section) I want to make changeable my own filter label). Is there any way to do it? Thanks in advance))

1

1 Answers

0
votes

To add your own section with settings under WooCommerce customize panel, just add follows codes snippets in your active theme's functions.php -

add_action( 'customize_register', 'my_custom_customize_register', 99 );
function my_custom_customize_register( $wp_customize ) {
    $wp_customize->add_section(
        'my_wc_custom_section',
        array(
            'title'    => __( 'My Custom Section', 'text-domain' ),
            'priority' => 20,
            'panel'    => 'woocommerce',
            'description' => '', 
        )
    );
    $wp_customize->add_setting( 'my_wc_custom_section_settings', array( 'transport' => 'postMessage' ) );
    $wp_customize->add_control( 'my_wc_custom_section_settings_control', 
        array(
            'label'     => __( 'Custom Text', 'text-domain' ),
            'type'      => 'text',
            'settings'  => 'my_wc_custom_section_settings',
            'section'   => 'my_wc_custom_section',
            'priority'  => 20,
        ) 
    );
}

To display your saved field's value from your custom section settings, just use follows -

echo get_theme_mod( 'my_wc_custom_section_settings' );

Thats it.