:
<?php
global $post, $product;
$term_list = wp_get_post_terms($post->ID, 'product_cat', array("fields" => "all"));
$cat_id = ($term_list[0]->parent);
$cat_url = get_term_link ($cat_id, 'product_cat');
$term = get_term( $cat_id, 'product_cat' );
$name = $term->name;
echo "Artist: <a href='".esc_url($cat_url)."'>".$name."</a>";
?>
:
WooCommerce , , , "" .
, - .
:
<?php
global $post, $product;
$term_list = wp_get_post_terms($post->ID, 'product_cat', array("fields" => "all"));
$cat_id = ($term_list[0]->parent);
$termchildren = get_term_children( '90' , 'product_cat' );
$new_cat_id = $termchildren[2];
$cat_url = get_term_link ($new_cat_id, 'product_cat');
$term = get_term( $new_cat_id, 'product_cat' );
$name = $term->name;
echo "Artist: <a href='".esc_url($cat_url)."'>".$name."</a>";
?>
(02 2015 .)
<?php
global $post, $product;
$cat_array = array();
$term_list = wp_get_post_terms($post->ID, 'product_cat', array("fields" => "all"));
foreach($term_list as $cat_list)
{
array_push($cat_array, $cat_list->term_id);
}
$cat_id = ($term_list[0]->parent);
$termchildren = get_term_children( '90' , 'product_cat' );
$final_result = array_intersect($cat_array,$termchildren);
$final_cat_result = array_values($final_result);
$new_cat_id = $final_cat_result[0];
$cat_url = get_term_link ($new_cat_id, 'product_cat');
$term = get_term( $new_cat_id, 'product_cat' );
$name = $term->name;
echo "Artist: <a href='".esc_url($cat_url)."'>".$name."</a>";
?>
: 1 $post $product . , , , .
: 2 **. .
: 3 wp_get_post_terms ( woocommerce - ). , , ID, name .. ..
: 4 , . term_id. array_push, 2. term_id.
: 9 get_term_children, , term ID fixed.It .
: 10 array_intersect . ( , ).
: 11 array_values . ( , :))
: 12 , one , term ID. ( it.Now ID)
: 13 .
: 15 , 14, .
: 16 , !