admin管理员组文章数量:1289635
Please help me with the following question.
I want to display an image in an additional TAB on the single product page (THIS PART WORKS ;-)). Sofar i can display the TAB and the image that has an URL on the product regular data (added field in the product adminstration. custom field = _product_tech)
BUT NOW: how can i check the custom field ? When it has no value it should display a placeholder image or better, a shortcode.
this is my code:
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['desc_tab'] = array(
'title' => __( 'Technische informatie', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
$prod_id = get_the_ID();
echo'<a class="shutter" title="technische gegevens" href="'.get_post_meta($prod_id,'_product_tech',true).'"><img width="750" height="100%" src="'.get_post_meta($prod_id,'_product_tech',true).'"></a>';
}
Please help me with the following question.
I want to display an image in an additional TAB on the single product page (THIS PART WORKS ;-)). Sofar i can display the TAB and the image that has an URL on the product regular data (added field in the product adminstration. custom field = _product_tech)
BUT NOW: how can i check the custom field ? When it has no value it should display a placeholder image or better, a shortcode.
this is my code:
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['desc_tab'] = array(
'title' => __( 'Technische informatie', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
$prod_id = get_the_ID();
echo'<a class="shutter" title="technische gegevens" href="'.get_post_meta($prod_id,'_product_tech',true).'"><img width="750" height="100%" src="'.get_post_meta($prod_id,'_product_tech',true).'"></a>';
}
Share
Improve this question
asked Jul 7, 2021 at 12:23
Coen van tartwijkCoen van tartwijk
1
1 Answer
Reset to default 0You can use empty, to check your variable.
Something like this
$prod_id = get_the_ID();
if (!empty(get_post_meta($prod_id,'_product_tech',true))) {
echo'<a class="shutter" title="technische gegevens" href="'.get_post_meta($prod_id,'_product_tech',true).'"><img width="750" height="100%" src="'.get_post_meta($prod_id,'_product_tech',true).'"></a>';
} else {
//Is empty
}
本文标签: phpif getpostmeta is empty echo a placeholder or shortcode
版权声明:本文标题:php - if get_post_meta is empty echo a placeholder or shortcode 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741459039a2379927.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论