How to Add Settings to a Section in WooCommerce

You need to filter the output of woocommerce_get_sections_products (or similar).

For example, let’s add the sample settings we discussed above to the new wcslider section we just created.

 * Add settings to the specific section we created before
add_filter( 'woocommerce_get_settings_products', 'wcslider_all_settings', 10, 2 );
function wcslider_all_settings( $settings, $current_section ) {
	 * Check the current section is what we want
	if ( $current_section == 'wcslider' ) {
		$settings_slider = array();
		// Add Title to the Settings
		$settings_slider[] = array( 'name' => __( 'WC Slider Settings', 'text-domain' ), 'type' => 'title', 'desc' => __( 'The following options are used to configure WC Slider', 'text-domain' ), 'id' => 'wcslider' );
		// Add first checkbox option
		$settings_slider[] = array(
			'name'     => __( 'Auto-insert into single product page', 'text-domain' ),
			'desc_tip' => __( 'This will automatically insert your slider into the single product page', 'text-domain' ),
			'id'       => 'wcslider_auto_insert',
			'type'     => 'checkbox',
			'css'      => 'min-width:300px;',
			'desc'     => __( 'Enable Auto-Insert', 'text-domain' ),
		// Add second text field option
		$settings_slider[] = array(
			'name'     => __( 'Slider Title', 'text-domain' ),
			'desc_tip' => __( 'This will add a title to your slider', 'text-domain' ),
			'id'       => 'wcslider_title',
			'type'     => 'text',
			'desc'     => __( 'Any title you want can be added to your slider with this option!', 'text-domain' ),
		$settings_slider[] = array( 'type' => 'sectionend', 'id' => 'wcslider' );
		return $settings_slider;
	 * If not, return the standard settings
	} else {
		return $settings;

We’re hooking into the same woocommerce_get_sections_products filter, but this time doing a check that the $current_section matches our earlier defined custom section (wcslider), before adding in our new settings.

Add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Dessky Snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be overwritten completely when you update the theme.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)