【发布时间】:2019-04-01 20:51:28
【问题描述】:
我正在尝试在 woo commerce 产品的快速编辑功能中添加我的自定义输入字段。
我在我的产品中创建了一个自定义输入字段。如果我直接进入每个产品的编辑页面,我只能编辑和保存这个自定义输入字段。
创建自定义输入字段:
function cfwc_create_custom_field() {
$args = array(
'id' => 'custom_product_code',
'label' => __( 'Product Code:', 'cfwc' ),
'class' => 'cfwc-custom-field',
'desc_tip' => false,
'description' => __( '', 'ctwc' ),
);
woocommerce_wp_text_input( $args );
}
add_action( 'woocommerce_product_options_general_product_data', 'cfwc_create_custom_field' );
保存自定义输入字段:
function cfwc_save_custom_field( $post_id ) {
$product = wc_get_product( $post_id );
$title = isset( $_POST['custom_product_code'] ) ? $_POST['custom_product_code'] : '';
$product->update_meta_data( 'custom_product_code', sanitize_text_field( $title ) );
$product->save();
}
add_action( 'woocommerce_process_product_meta', 'cfwc_save_custom_field' );
如果我在编辑页面中编辑产品,此代码可以正常工作。我想要的是在我的产品的快速编辑功能中编辑这个自定义输入字段,这样用户就不需要去每个产品的编辑页面。
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: wordpress woocommerce