• Resolved adpu

    (@adpu)


    Hi,

    I have created a snippet code for print a custom field of woocommerce product.
    My custom field is a subtitle, and it has this id: _subtitol_products

    This is my code:

    add_action( ‘woocommerce_single_product_summary’, ‘display_subtitol_products’, 9 );

    function display_subtitol_products() {
    global $product;
    //echo $product->id;
    // echo get_post_meta(361, ‘_subtitol_products’, true);
    echo get_post_meta( $product->id, ‘_subtitol_products’, true);
    }

    The first comment line it works, the second comment line it works too.
    The get_post_meta not works.

    Can you help me ?

    Thanks and regards

    • This topic was modified 7 years, 4 months ago by adpu.
Viewing 2 replies - 1 through 2 (of 2 total)
  • I check code and it work, Question is, you call it in correct file? like in functions.php?
    Second line you mean echo get_post_meta(361, ‘_subtitol_products’, true); ?
    Did you receive correct product ID ?

    Try use default WP theme, and try this code, maybe somewhere in your theme is hook that mess with this action.

    Thread Starter adpu

    (@adpu)

    Thanks Isu for your answer,

    This code is inside WordPress snippet plugin, I will try to put it inside functions.

    The code line :

    echo get_post_meta(361, ‘_subtitol_products’, true);

    It works well, I will try to change my theme to default WP theme, maybe this is the problem.

    Thanks for your support,

    Have a nice day,

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Why this snippet not work ?’ is closed to new replies.