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 | |
/** | |
* WooCommerce product category list with child categories | |
*/ | |
// Function to get top-level "product_cat" terms with their child terms (1 level only). | |
function pb_get_woocommerce_categories() { | |
$taxonomy = 'product_cat'; | |
// If you wish to exclude "Uncategorized" term ID, use this function - https://gist.github.com/bencicpatricija/3eec5e8345202c7b06d4838219dff112 |
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
/** | |
* Get "Uncategorized" term ID from "product_cat" taxonomy. | |
*/ | |
function pb_get_product_uncategorized_term_id() { | |
$uncategorized_term_id = get_term_by( 'slug', 'uncategorized', 'product_cat')->term_id; | |
if ( ! class_exists( 'woocommerce' ) || ! $uncategorized_term_id ) { | |
return false; | |
} else { | |
return $uncategorized_term_id; |
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
/** | |
* Filter to allow custom non-hierarchical taxonomy terms in the permalinks for products. | |
* | |
* @param string $permalink The existing permalink URL. | |
* @param WP_Post $post WP_Post object. | |
* @return string | |
*/ | |
function pb_custom_product_post_type_link( $permalink, $post ) { | |
// Abort if post is not a product. | |
if ( 'product' !== $post->post_type ) { |