php – if get_post_meta is empty echo a placeholder or shortcode

Question

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
Coen van tartwijk 4 weeks 2021-07-07T07:23:40-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse