0

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>';
        
        }
0

You 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
}
1
  • Thanks! for sharing this answer, it helped ! Jul 12 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.