[英]Hide custom field label on the order edit page (backend), if it is empty in WooCommerce
I'm using the following code to display field label for "shipping_company" field, on the edit page.我正在使用以下代码在编辑页面上显示“shipping_company”字段的字段 label。
// Display field value for shipping company field
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'delivery_date_and_time', 10, 1 );
function delivery_date_and_time($order){
echo '<p><strong>'.__('Delivery Date & Time').':</strong> ' . get_post_meta( $order->get_id(),
'_shipping_company', true ) . '</p>';
}
Now, I'm trying to hide the label, if it was not filled by the customer, when they placed the order.现在,如果客户在下订单时没有填写 label,我正在尝试隐藏它。
You could add an if condition to get_post_meta
, if NOT empty.. echo如果不为空,您可以向
get_post_meta
添加一个 if 条件.. echo
// Display field value for shipping company field
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'delivery_date_and_time', 10, 1 );
function delivery_date_and_time($order) {
$shipping_company = get_post_meta( $order->get_id(), '_shipping_company', true );
// NOT empty
if ( ! empty ( $shipping_company ) ) {
echo '<p><strong>' . __( 'Delivery Date & Time', 'woocommerce' ) . ':</strong> ' . $shipping_company . '</p>';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.