wp_customize – detect post type to show/hide customizer options

Customizer Controls can be displayed based on context. With active_callback API introduced in WordPres 4.0, you can control where to show your specific options. Add your customizer options like this with the optional active_callback argument.

$wp_customize->add_control( 'wc_cart_page_option', array(
'label'           => esc_html__( 'Cart Page Options' ),
'section'         => 'wc_cart',
'active_callback' => 'estore_is_cart',
));

Now create a function called ‘estore_is_cart’ to check if user is previewing the cart page.

function estore_is_cart(){
  if( is_cart() ) {
    return true;
  } else {
    return false;
  }
}

Note: You can also directly pass is_cart function check to ‘active_callback’ argument.

Check contextual controls section in the blog post: https://make.wordpress.org/core/2014/07/08/customizer-improvements-in-4-0/