简体   繁体   中英

Conditional tag for Woocommerce paged product category pages

I need to add some code to certain Woocommerce product category archies, but only to the first page, neer the paginated archives. Is there a conditional tag for that? I tried

if( is_product_category( array( 'category1', 'category' ) ) || !is_paged )

but it did not work.

You can use woocommerce wc_get_loop_prop() dedicated function with the 'is_paginated' and/or 'current_page' arguments as follow

if( is_product_category( array( 'category1', 'category' ) ) && ( ( wc_get_loop_prop( 'is_paginated' ) && wc_get_loop_prop( 'current_page' ) == 1 ) || ! wc_get_loop_prop( 'is_paginated' ) ) ) {
    // Here goes other code
}

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