简体   繁体   中英

Display a shorcode below products in Woocommerce Storefront Category archives?

I need to add the following shortcode [logoshowcase cat_id="427"] in all product category pages, so it displays below of the product listed

I'm trying:

add_action( 'woocommerce_after_main_content', 'add_my_text', 20 );
function add_my_text() {
    echo do_shortcode( '[logoshowcase cat_id="427"]' );
}

But it isn't working as I would like, specifically in product category archive pages.

Sorry but this hook works on last woocommerce version, but as storefront sidebar uses this hook too, you will need to lower the hook priority under 10 if you want to display your shortcode below the products loop in archives and single product pages, like:

add_action( 'woocommerce_after_main_content', 'add_my_text', 9 ); 
function add_my_text() {
    // Only on Woocommerce Category archive pages
    if ( is_product_category() ) {
        echo do_shortcode( '[logoshowcase cat_id="427"]' ); 
    }
}

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM