How to hook using add_filter()

124 Views Asked by At

I want to hook my project to a new WooCoomerce tab.

I am able to hook it to "woocommerce_short_description" or "the_content" but not my own tab.

add_filter( 'the_content', array( 'My_Music', 'render_song' ), 10 );

Here is a fragment of my own Lyrics tab.

// Add product custom "Lyrics" tab
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {

    $tabs['test_tab'] = array(
        'title'     => __( 'Lyrics', 'woocommerce' ),
        'priority'  => 50,
        'callback'  => 'lyrics_product_tab_content'
    );

    return $tabs;
}

// The Lyrics tab content
function lyrics_product_tab_content()  {
    // The new tab content
    $prod_id = get_the_ID();
    echo'<div><p>'.get_post_meta( get_the_ID(), '_lyrics_tab' ,true ).'</p></div>';
}
1

There are 1 best solutions below

2
On

It looks like you don't have the data in postmeta table. Please try the following

function lyrics_product_tab_content()  {
  echo "string";
  // The new tab content
  echo $prod_id = get_the_ID();
  echo'<div><p>'.get_post_meta( get_the_ID(), '_lyrics_tab' ,true ).' Check Output</p></div>';
}

This will show some testing "string & check" which will give you the idea if your callback is working or not.