I've created a do_action('after_product_tabs)
hook that I hope to programmatically echo an image under specific product categories, but I'm running into a bug. I'm able to echo out a div
as a test for the action hook, but my conditional logic is breaking. Any help would be very much appreciated:
Here's the function:
function after_product_tabs() {
do_action('after_product_tabs'); //creates the action hook
};
function display_prewired_image() {
echo '<div class="test" style="clear: both;">'.$home_url.'</div>'; // This prints!
if( has_term( 'strat_pickups', 'product_cat' ) ) {
echo' <p>DEBUG ME</p>'; // This breaks
}
}
add_action('after_product_tabs', 'display_prewired_image');
I've also Tried:
1.) Passing in Global Variable:
function display_prewired_image() {
global $product;
$prod_id = $product->get_id();
if( has_term( 'strat_pickups', 'product_cat', $prod_id ) ) {
echo' <p>DEBUG ME</p>';
}
}
2.) Changing the conditional logic from product categories to is_single()
, which works, so I know my problem is within the logic of strat_pickups
:
function display_prewired_image() {
global $product;
if ( is_a( $product, 'WC_Product' ) ) {
// Get product ID
$prod_id = $product->get_id();
if( is_single('354') ) {
echo '<h1 style="red!important; clear: both;">DEBUG ME</h1>';
}
} else {
echo 'No product found!';
}
}
add_action( 'after_product_tabs', 'display_prewired_image' );
For more info, I'm customizing the tabs.php template in Woocommerce. Would that not have access to the $product variable?