在 Woocommerce 中保存新的属性分类
我已经在 woocommerce_attribute 分类法中注册了新列,并且我想将自定义字段保存到新列中,我使用 woocommerce_after_edit_attribute_fields 挂钩来显示输入,并使用 woocommerce_attribute_updated/added 来捕获新属性的数据,但是当我尝试时更新平板电脑确实什么都不做,也许 woocommerce 操作/过滤器有一些我不知道的解决方案...感谢您的帮助:)
add_action( 'woocommerce_attribute_added', 'my_save_wc_attribute_my_field',10,2 );
add_action( 'woocommerce_attribute_updated', 'my_save_wc_attribute_my_field',10,2 );
function my_save_wc_attribute_my_field($id,$data ) {
if ( is_admin() && isset( $_POST['my_field'] ) ) {
global $wpdb;
$attribute_name= 'wwowowowwo';
$attribute_slug = $data['attribute_slug'];
$attribute_label = $data['attribute_label'];
$attribute_orderby = $data['attribute_orderby'];
$attribute_public = $data['attribute_public'];
$attribute_maple = $_POST['my_field'];
$arrd = array(
'attribute_name' => $attribute_name,
'attribute_label' => $attribute_label,
'attribute_orderby' => $attribute_orderby,
'attribute_public' => $attribute_public,
'maple_attribute_types' => sanitize_text_field($_POST['my_field']),
);
$arrid = array(
'ID' => $id,
);
// save new field into attribute taxonomies
$wpdb->update("wp_woocommerce_attribute_taxonomies", $arrd,$arrid);
echo $attribute_orderby;
echo $id;
echo $attribute_maple;
}
}
i've register new column in woocommerce_attribute taxonomies, and i want to save my custom field to my new column, i'm using woocommerce_after_edit_attribute_fields hook to display an input and woocommerce_attribute_updated/added to catch the data of a new attribute, but when i try update the tableit dosent really do nothing, maybe there is some solution with woocommerce action/filter that i dont know about ... thank for any help :)
add_action( 'woocommerce_attribute_added', 'my_save_wc_attribute_my_field',10,2 );
add_action( 'woocommerce_attribute_updated', 'my_save_wc_attribute_my_field',10,2 );
function my_save_wc_attribute_my_field($id,$data ) {
if ( is_admin() && isset( $_POST['my_field'] ) ) {
global $wpdb;
$attribute_name= 'wwowowowwo';
$attribute_slug = $data['attribute_slug'];
$attribute_label = $data['attribute_label'];
$attribute_orderby = $data['attribute_orderby'];
$attribute_public = $data['attribute_public'];
$attribute_maple = $_POST['my_field'];
$arrd = array(
'attribute_name' => $attribute_name,
'attribute_label' => $attribute_label,
'attribute_orderby' => $attribute_orderby,
'attribute_public' => $attribute_public,
'maple_attribute_types' => sanitize_text_field($_POST['my_field']),
);
$arrid = array(
'ID' => $id,
);
// save new field into attribute taxonomies
$wpdb->update("wp_woocommerce_attribute_taxonomies", $arrd,$arrid);
echo $attribute_orderby;
echo $id;
echo $attribute_maple;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用了 创建自定义属性中的函数...
和里面的
process_Add_attribute
我已经删除了I've used the function from Creating custom attribute...
and inside
process_Add_attribute
I've removed