I am trying to get the current woocommerce product title on functions.php page. I tried to use all the functions like $product->ID, get_the_title etc but no one is working..
function custom_title() {
global $new_myKey, $post, $product;
$cache_key = 'myKey';
$myKey = wp_cache_get( $cache_key );
if( false === $myKey ){
$new_myKey = get_the_title();
wp_cache_set( $myKey, $new_myKey );
}
}
add_action( 'after_setup_theme', 'custom_title' );
At this point $new_myKey = get_the_title(); I want to get the dynamic product title. Is there any way to do?