【发布时间】:2019-10-23 03:42:33
【问题描述】:
我为我的 woocommerce 产品创建了客户数据字段。我想在预订的每一步都显示此信息(日期、时间和地点)。在结帐页面,订单详情和电子邮件。请你帮助我好吗 ?在下面找到我用于 md 自定义字段的代码。非常感谢
add_action( 'woocommerce_product_options_inventory_product_data', 'woocom_inventory_product_data_custom_field' );
function woocom_Inventory_product_data_custom_field() {
// Create a custom text field
// Text Field
woocommerce_wp_text_input(
array(
'id' => 'venue',
'label' => __( 'Venue', 'woocommerce' ),
'placeholder' => 'Venue',
'desc_tip' => 'true',
'description' => __( 'Enter the location here.', 'woocommerce' )
)
);
woocommerce_wp_text_input(
array(
'id' => 'date',
'label' => __( 'Date', 'woocommerce' ),
'placeholder' => 'date',
'desc_tip' => 'true',
'description' => __( 'Enter the date here.', 'woocommerce' )
)
);
woocommerce_wp_text_input(
array(
'id' => 'time',
'label' => __( 'Time', 'woocommerce' ),
'placeholder' => 'time',
'desc_tip' => 'true',
'description' => __( 'Enter the time here.', 'woocommerce' )
)
);
}
// Hook to save the data value from the custom fields
add_action( 'woocommerce_process_product_meta', 'woocom_save_inventory_proddata_custom_field' );
/** Hook callback function to save custom fields information */
function woocom_save_inventory_produdata_custom_field( $post_id ) {
// Save Text Field
$text_field = $_POST['venue'];
if( ! empty( $text_field ) ) {
update_post_meta( $post_id, 'venue', esc_attr( $text_field ) );
}
$text_field = $_POST['date'];
if( ! empty( $text_field ) ) {
update_post_meta( $post_id, 'date', esc_attr( $text_field ) );
}
$text_field = $_POST['time'];
if( ! empty( $text_field ) ) {
update_post_meta( $post_id, 'time', esc_attr( $text_field ) );
}
}
【问题讨论】:
标签: wordpress email woocommerce custom-fields