Sunday, January 23rd, 2022

How do I add custom widget woocommerce shop page with php?

I want to make a widget that will appear only on the shop page, but I didn’t get any result.

functions.php

function kucuksun_widgets_init() {
    register_sidebar(
        array(
            'name'          => esc_html__( 'Sidebar', 'kucuksun' ),
            'id'            => 'sidebar-1',
            'description'   => esc_html__( 'Add widgets here.', 'kucuksun' ),
            'before_widget' => '<section id="%1$s" class="widget %2$s">',
            'after_widget'  => '</section>',
            'before_title'  => '<h2 class="widget-title">',
            'after_title'   => '</h2>',
        ),
        register_sidebar(
        array(
            'name'          => esc_html__( 'Shop', 'kucuksun' ),
            'id'            => 'shop',
            'description'   => esc_html__( 'Add widgets here.', 'kucuksun' ),
            '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', 'kucuksun_widgets_init' );

After my code: sidebar.php

<?php

if ( ! is_active_sidebar( 'sidebar-1' ) ) {
    return;
}
?>

<aside id="secondary" class="widget-area">
    <?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside>

I’m not exactly sure, but I need to print this
woocommerce.php dynamic_sidebar( 'shop' );

Source link