6

For example if there is a Customizer section that focuses on Woocommerce options, I'd like the user to be on the shop page for that, to see all these changes, live.

I can do http://127.0.0.1/wp-admin/customize.php?url=http://127.0.0.1/shop&autofocus[section]=woocommerce as a link in the admin panel, which will put customizer on that URL, with the relevant section open, but that's not ideal.

I would like the customizer to automatically navigate to the specified url when the user clicks on any section.

Is there any way to have onSectionClick event and then set previewUrl to something?

  • Whilst your intentions are innocent, I would argue this might be confusing/anti-user-friendly. By all means, use the contextual logic in the customizer API to only show sections/controls when on the shop, but don't do it the other way around. What if a user is customizing & flicking between sections? They click WooCommerce and bam, their preview window gets redirected to the shop - not necessarily what they wanted or intended to do. – TheDeadMedic May 14 '16 at 17:47
  • Have you ever found an answer to this question? – Snowball Jul 21 '16 at 1:35
1

You could use active_callback property to delegate section visibility depending on current preview screen.

$wp_customize->add_section( 'my-section',
array(
    'title' => __( 'Section Title' ),
    'active_callback' => 'is_shop',
) );

Or custom

$wp_customize->add_section( 'my-section',
array(
    'title' => __( 'Section Title' ),
    'active_callback' => 'is_custom_condition',
) );
function is_custom_condition(){
    $condition_is_met = //Some boolean returning logic;
    if( ! $condition_is_met ){
         return false;
    }
    return true;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.