Skip to content

Commit

Permalink
fix single product default sidebar behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
francgrasso committed Jul 7, 2020
1 parent 7faa5ca commit 508c735
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
35 changes: 18 additions & 17 deletions inc/customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,24 @@ function yith_proteo_customize_shop_register( $wp_customize ) {
)
);

// Single Product default Sidebar Chooser.
$wp_customize->add_setting(
'yith_proteo_single_product_default_sidebar',
array(
'default' => 'shop-sidebar',
'sanitize_callback' => 'yith_proteo_sanitize_select',
)
);
$wp_customize->add_control(
'yith_proteo_single_product_default_sidebar',
array(
'type' => 'select',
'label' => esc_html__( 'Choose the sidebar to use on single product page', 'yith-proteo' ),
'section' => 'yith_proteo_product_page_management',
'description' => esc_html__( 'You can adjust the settings from product edit view.', 'yith-proteo' ),
'choices' => wp_list_pluck( $GLOBALS['wp_registered_sidebars'], 'name' ),
)
);
// Force all products to use the same sidebar.
$wp_customize->add_setting(
'yith_proteo_product_page_sidebar_force',
Expand All @@ -1619,23 +1637,6 @@ function yith_proteo_customize_shop_register( $wp_customize ) {
),
)
);
// Single Product default Sidebar Chooser.
$wp_customize->add_setting(
'yith_proteo_single_product_default_sidebar',
array(
'default' => 'shop-sidebar',
'sanitize_callback' => 'yith_proteo_sanitize_select',
)
);
$wp_customize->add_control(
'yith_proteo_single_product_default_sidebar',
array(
'type' => 'select',
'label' => esc_html__( 'Choose the sidebar to use for all products', 'yith-proteo' ),
'section' => 'yith_proteo_product_page_management',
'choices' => wp_list_pluck( $GLOBALS['wp_registered_sidebars'], 'name' ),
)
);

/**
* Product Category page management
Expand Down
4 changes: 4 additions & 0 deletions inc/metaboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ function yith_proteo_sidebar_chooser_html( $post ) {
?>

<select name="sidebar_chooser" id="sidebar_chooser" class="components-text-control__input">
<option
value="inherit" <?php echo ( yith_proteo_sidebar_get_meta( 'sidebar_position' ) === 'inherit' ) ? 'selected' : ''; ?>>
<?php esc_html_e( 'inherit', 'yith-proteo' ); ?>
</option>
<?php foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) { ?>
<option
value="<?php echo esc_attr( ucwords( $sidebar['id'] ) ); ?>" <?php echo ( yith_proteo_sidebar_get_meta( 'sidebar_chooser' ) === esc_attr( ucwords( $sidebar['id'] ) ) ) ? 'selected' : ''; ?>>
Expand Down
7 changes: 5 additions & 2 deletions sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@
$sidebar = get_theme_mod( 'yith_proteo_product_tax_page_sidebar', 'shop-sidebar' );
}
}

if ( is_home() ) {
$sidebar = get_theme_mod( 'yith_proteo_blog_sidebar', 'sidebar-1' );
}
if ( is_product() && get_theme_mod( 'yith_proteo_product_page_sidebar_force', 'no' ) === 'yes' ) {
if ( is_product() && 'yes' === get_theme_mod( 'yith_proteo_product_page_sidebar_force', 'no' ) ) {
dynamic_sidebar( get_theme_mod( 'yith_proteo_single_product_default_sidebar', 'shop-sidebar' ) );
} elseif ( is_product() && 'inherit' === $sidebar ) {
dynamic_sidebar( get_theme_mod( 'yith_proteo_single_product_default_sidebar', 'shop-sidebar' ) );
} elseif ( ( is_single() || is_page() ) && 'inherit' === $sidebar ) {
dynamic_sidebar( get_theme_mod( 'yith_proteo_default_sidebar', 'sidebar-1' ) );
} elseif ( ! empty( $sidebar ) ) {
dynamic_sidebar( $sidebar );
} else {
Expand Down

0 comments on commit 508c735

Please sign in to comment.