Last active
May 20, 2022 16:37
-
-
Save rushijagani/08eed09423b3c88d982f8f31c82f38fa to your computer and use it in GitHub Desktop.
Show all the categories list for each product on the shop page in Astra.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Shop page - Show all categories for each product on shop page | |
*/ | |
if ( ! function_exists( 'astra_woo_shop_parent_category' ) ) : | |
function astra_woo_shop_parent_category() { | |
if ( apply_filters( 'astra_woo_shop_parent_category', true ) ) : ?> | |
<span class="ast-woo-product-category"> | |
<?php | |
global $product; | |
$product_categories = function_exists( 'wc_get_product_category_list' ) ? wc_get_product_category_list( get_the_ID(), ', ', '', '' ) : ''; | |
$product_categories = htmlspecialchars_decode( strip_tags( $product_categories ) ); | |
if ( $product_categories ) { | |
list( $parent_cat ) = explode( ';', $product_categories ); | |
echo esc_html( $parent_cat ); | |
} | |
?> | |
</span> | |
<?php | |
endif; | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good!