wordpress - 在 woocommerce 产品的 quickedit 函数中添加我的自定义输入字段
问题描述
我正在尝试在 woo 商务产品的快速编辑功能中添加我的自定义输入字段。
我在我的产品中创建了一个自定义输入字段。如果我直接进入每个产品的编辑页面,我只能编辑和保存这个自定义输入字段。
创建自定义输入字段:
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' );
如果我在编辑页面中编辑产品,此代码可以正常工作。我想要的是在我的产品的快速编辑功能中编辑这个自定义输入字段,这样用户就不需要去每个产品的编辑页面。
任何帮助,将不胜感激。谢谢。
解决方案
将您的上述功能添加cfwc_create_custom_field
到操作中,例如-
add_action( 'woocommerce_product_quick_edit_end', 'cfwc_create_custom_field' );
并将您的数据保存在do_action( 'woocommerce_product_quick_edit_save', $product );
挂钩中。
推荐阅读
- asp.net-core - IdentityServer4 与 AspNetIdentity。如何让 WebApi 访问 UserDb
- java - 使用 itext 时出错
- html - 如何使用纯 CSS 创建带有虚线的票形状?
- html - 我基于复选框单击显示 2 个图标,但如果我选择 >1,则不应出现复选框
- java - 从 String java 中删除未知数量的字符
- node.js - nodejs - Mongoose 5.3.8 - GeoJSON 查询不起作用
- swift - BaseObject 可以有 NSObject、Mappable 和 Object swift
- c++ - 更改静态文本 C++ 的颜色
- python - 在 python 中是否有类似 ansible 的模块?
- asp.net-mvc - Ck 编辑器不在服务器上工作,但它在本地机器 asp.net mvc 上工作