Display Default Content If Custom Field Is Empty

Question

I am using Woocommerce multi vendor.

I have a custom field I would like it to display default content "Currently Shipping World Wide" if the vendor has not added any content to the field.

The code works well if the custom field has content.

But it is not working if the custom field is empty.

The code I have is below.

add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );

function woo_new_product_tab( $tabs ) {
$tabs[‘new_tab’] = array(
‘title’ => __( ‘Shipping To’, ‘woocommerce’ ),
‘priority’ => 5,
‘callback’ => ‘woo_new_product_tab_content’
);
return $tabs;
}

function woo_new_product_tab_content() {
global $WCFMu;
$product_id = get_the_ID();
if ( $product_id ) {
$wcfm_product_custom_fields = (array) get_option( ‘wcfm_product_custom_fields’ );
if ( $wcfm_product_custom_fields && is_array( $wcfm_product_custom_fields ) && ! empty( $wcfm_product_custom_fields ) ) {
$fields = ”;
foreach ( $wcfm_product_custom_fields as $wpcf_index => $wcfm_product_custom_field ) {
if ( ! isset( $wcfm_product_custom_field[‘enable’] ) )
continue;
$visibility = isset( $wcfm_product_custom_field[‘visibility’] ) ? $wcfm_product_custom_field[‘visibility’] : ”;
if ( $visibility )
continue; //we are not showing the fields that are allready visible in some other areas of the product

if (empty($wcfm_product_custom_field)) {

echo '<p>Currently Shipping World Wide</p>';

} else { echo $WCFMu->wcfmu_customfield_support->get_wcfm_custom_field_display_data( $product_id, $wcfm_product_custom_field );}

}

        }
    }

}

0
Martin Mavengere 2 months 0 Answers 11 views 0

Leave an answer