Created
January 22, 2019 12:14
-
-
Save finalwebsites/10bd697cb1cd9b5b9617a9a525aedae7 to your computer and use it in GitHub Desktop.
Add parent product category names to the woocommerce_page_title() function (hook)
This file contains 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 | |
add_filter( 'woocommerce_page_title', 'custom_woocommerce_page_title'); | |
function custom_woocommerce_page_title( $page_title ) { | |
$queried_object = get_queried_object(); | |
if ($queried_object->taxonomy == 'product_cat') { | |
$tid = $queried_object->parent; | |
while ($tid > 0) { | |
if ($parent_obj = get_term($tid, 'product_cat')) { | |
$tid = $parent_obj->parent; | |
$page_title = $parent_obj->name . ' > ' . $page_title; | |
} | |
} | |
} | |
return $page_title; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment