K
K
Konstantin2020-08-09 13:30:38
WordPress
Konstantin, 2020-08-09 13:30:38

How to create custom sidebar in woocommerce?

I don't know how to display my sidebar on woocommerce pages.

Registered sidebar in functions:

//второй сайдбар под шоп

function grad_market_widgets_init1() {
  register_sidebar(
    array(
      'name'          => esc_html__( 'Sidebar-shop', 'grad_market' ),
      'id'            => 'sidebar-2',
      'description'   => esc_html__( 'Add widgets here.', 'grad_market' ),
      'before_widget' => '<section id="%1$s" class="widget %2$s">',
      'after_widget'  => '</section>',
      'before_title'  => '<h2 class="widget-title">',
      'after_title'   => '</h2>',
    )
  );
}
add_action( 'widgets_init', 'grad_market_widgets_init1' );


I created the sidebar-shop.php sidebar template itself and put it in the root folder of the theme

. Now I want to display it in woocommerce, but I don’t know what to enter:

<?
/**
 * Hook: woocommerce_sidebar.
 *
 * @hooked woocommerce_get_sidebar - 10
 */
do_action( 'woocommerce_sidebar' ); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Litvinenko, 2020-08-09
@gradk

// отключение сайдбара
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );

add_action( 'woocommerce_sidebar', 'standart_sidebar', 10 );
function standart_sidebar() {
  get_template_part( 'sidebar' );
  //get_sidebar();
}

both options work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question