Skip to content

Instantly share code, notes, and snippets.

@rushijagani
Last active May 20, 2022 16:37
Show Gist options
  • Save rushijagani/08eed09423b3c88d982f8f31c82f38fa to your computer and use it in GitHub Desktop.
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.
<?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;
@laura8095
Copy link

Good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment