Skip to content

Commit

Permalink
Add WC sidebar and related position setting
Browse files Browse the repository at this point in the history
Close #315.
  • Loading branch information
Misplon committed Dec 25, 2017
1 parent 00d72c0 commit 84444df
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
12 changes: 12 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ function siteorigin_north_widgets_init() {
'after_title' => '</h2>',
) );

if ( function_exists( 'is_woocommerce' ) ) {
register_sidebar( array(
'name' => esc_html__( 'Shop Sidebar', 'siteorigin-north' ),
'id' => 'sidebar-shop',
'description' => esc_html__( 'Displays on WooCommerce pages.', 'siteorigin-north' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h3>',
) );
}

}
endif;
add_action( 'widgets_init', 'siteorigin_north_widgets_init' );
Expand Down
11 changes: 11 additions & 0 deletions inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,20 @@ function siteorigin_north_body_classes( $classes ) {
}

if ( class_exists( 'Woocommerce' ) ) {

if ( ! siteorigin_setting( 'masthead_text_above' ) && ! is_active_sidebar( 'topbar-sidebar' ) && ! is_store_notice_showing() ) {
$classes[] = 'no-topbar';
}

if ( siteorigin_setting( 'woocommerce_sidebar_position' ) == 'left' && ( is_woocommerce() || is_cart() || is_checkout() ) ) {
$classes[] = 'layout-sidebar-left';
}

if ( siteorigin_setting( 'woocommerce_sidebar_position' ) == 'none' && ( is_woocommerce() || is_cart() || is_checkout() ) ) {
$classes[] = 'no-active-sidebar';
}


} elseif ( ! siteorigin_setting( 'masthead_text_above' ) && ! is_active_sidebar( 'topbar-sidebar' ) ) {
$classes[] = 'no-topbar';
}
Expand Down
33 changes: 22 additions & 11 deletions inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,21 +461,31 @@ function siteorigin_north_woocommerce_settings( $settings ) {
),

'display_cart' => array(
'type' => 'checkbox',
'label' => esc_html__( 'Display Cart', 'siteorigin-north' ),
'type' => 'checkbox',
'label' => esc_html__( 'Display Cart', 'siteorigin-north' ),
'description' => esc_html__( 'Display WooCommerce cart in the main menu.', 'siteorigin-north' ),
),

'display_checkout_cart' => array(
'type' => 'checkbox',
'label' => esc_html__( 'Display Cart in Checkout', 'siteorigin-north' ),
'type' => 'checkbox',
'label' => esc_html__( 'Display Cart in Checkout', 'siteorigin-north' ),
'description' => esc_html__( 'Display WooCommerce cart in the main menu on cart and checkout page.', 'siteorigin-north' ),
),

'display_quick_view' => array(
'type' => 'checkbox',
'label' => esc_html__( 'Display Quick View button', 'siteorigin-north' ),
)
'type' => 'checkbox',
'label' => esc_html__( 'Display Quick View button', 'siteorigin-north' ),
),

'sidebar_position' => array(
'type' => 'select',
'label' => esc_html__( 'Shop Sidebar Position', 'siteorigin-north' ),
'options' => array(
'left' => esc_html__( 'Left', 'siteorigin-north' ),
'right' => esc_html__( 'Right', 'siteorigin-north' ),
'none' => esc_html__( 'None', 'siteorigin-north' ),
),
),

)
)
Expand Down Expand Up @@ -1232,10 +1242,11 @@ function siteorigin_north_settings_defaults( $defaults ){
$defaults['footer_top_margin'] = '30px';

// WooCommerce defaults
$defaults['woocommerce_archive_columns'] = 3;
$defaults['woocommerce_display_cart'] = true;
$defaults['woocommerce_display_checkout_cart'] = false;
$defaults['woocommerce_display_quick_view'] = false;
$defaults['woocommerce_archive_columns'] = 3;
$defaults['woocommerce_display_cart'] = true;
$defaults['woocommerce_display_checkout_cart'] = false;
$defaults['woocommerce_display_quick_view'] = false;
$defaults['woocommerce_sidebar_position'] = 'right';

return $defaults;
}
Expand Down
20 changes: 20 additions & 0 deletions sidebar-shop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* The sidebar for WooCommerce shop pages.
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package siteorigin-north
* @license GPL 2.0
*/

if ( siteorigin_setting( 'woocommerce_sidebar_position' ) == 'none' ) return;
?>

<div id="secondary" class="widget-area" aria-label="<?php esc_attr_e( 'Shop Sidebar', 'siteorigin-north' ); ?>">
<?php if ( is_active_sidebar( 'sidebar-shop' ) ) {
dynamic_sidebar( 'sidebar-shop' );
} else {
dynamic_sidebar( 'main-sidebar' );
} ?>
</div><!-- #secondary -->
2 changes: 1 addition & 1 deletion woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
</main><!-- #main -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_sidebar( 'shop' ); ?>
<?php get_footer(); ?>

0 comments on commit 84444df

Please sign in to comment.