0

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?

Thanks & Regardsenter image description here

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • This was already answered here: https://stackoverflow.com/a/27394146/13004717 – Samih Soylu Jul 17 '20 at 09:57
  • There may be better filter or action for what you try to achieve. If you can explain what are you trying to do here, we can help you – melvin Jul 17 '20 at 09:58
  • @SamihSoylu I have already checked these answers, All are not working. – Inderpreet Singh Saini Jul 17 '20 at 09:59
  • @melvin actually I am trying to get the title on dokan support form. which is coming via dokan plugin. By default there is not any title displaying when we contact vendor. Please see the attached above picture. I am unable to findout any another better solution for this that's why I choose to use ''wp_cache_get" function. – Inderpreet Singh Saini Jul 17 '20 at 10:03
  • Is the form displayed in product page ? Have you checked the form rendering function to find any hooks to populate value ? – melvin Jul 17 '20 at 10:12
  • @melvin yes, I have displayed this form via popup which is a default dokan feature. this is the code: It displays popup according to the classes. So, when we try to get any info on this popup template it's not getting via functions. So, I thought if there is a way to save the variable in cache and can get it in popup that will be good.. – Inderpreet Singh Saini Jul 17 '20 at 10:34

0 Answers0