I'm having trouble getting a taxonomy term to display as the title for my product-post snippets. This is on a Wordpress site, using the Avada Theme, with Woocommerce and the Advanced Custom Fields plug-in. The taxonomy is generated by the Custom Taxonomies plug-in, and everything works great on the rest of the site.
So far I can get everything to show up in the right place, but the best I can do is "echo" a message. I was getting the ID number of the taxonomy terms before reading further into the topic, and swapped "object ID" with "term-name" in the ACF front-end, but now I can't get the ID or the title!
Please help, PHP is not my strong suit, so I'm sure this is a newbie oversight!
add_action( 'woocommerce_shop_loop_item_title', 'artist_link' );
function artist_link() {
$value = get_field("product_artist");
if($value)
{
echo "can't return value here, but I'd like the artist product term! ";
}
else
{
echo 'No Artist Entry';
}
}
This code snippet is from my functions.php file, as the Avada theme requires you to use the loop over a "single-XXX.php" file.
I should mention too this is a single choice from a multi select, and "product_artist" is from ACF, the Custom Taxonomy term ID is "artists".
Thanks!
*EDIT: for those who may have this problem in the future, this is what worked for me
add_action('woocommerce_shop_loop_item_title', 'artist_link');
function artist_link()
{
// Get the WooCommerce global variable for the current product
global $product;
if ($product instanceof \WC_Product) {
$value = get_field("product_artist", $product->get_id());
if ($value) {
echo $value->name;
} else {
echo 'Value falsey, do something with it here';
}
return;
}
echo 'No global product here';
}
Looks like I was trying to call a string and not an object (which is what $value is).