Displaying Advanced Custom Field (ACF) value in a WooCommerce hook

对着背影说爱祢 提交于 2019-12-01 11:36:18

Your problem is that you can't use echo with ACF the_field('my_field') , because when using the_field('my_field') is just like using echo get_field('my_field'), so you are trying to echo an echo. Instead use get_field('my_field') this way in your code:

add_action( 'woocommerce_single_product_summary', 'charting', 20 );

function charting() {
    if( !empty( get_field('size_chart') ) ) { // if your custom field is not empty…
        echo '<p><a href="' . get_field('size_chart') . '" data-rel="prettyPhoto">size guide</a></p>';
    }
    return;
}

After, I have add empty() function in your condition…

You can also try to return it instead of echo:

    return '<p><a href="' . get_field('size_chart') . '" data-rel="prettyPhoto">size guide</a></p>';

Reference:

I used this code and it worked well in local but when i upload function file in server it doesn,t work and it gives server error 500, so I had to remove this code again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!