Add a custom multi-select field to admin product options settings in Woocommerce(在 Woocommerce 中添加自定义多选字段以管理产品选项设置)
问题描述
我遵循了这个答案
这是我的代码:
这种选择字段仅适用于定义的 multiple
属性和值数组.所以你不能将它用于简单的 ID.如果您添加到您的选择字段 multiple="multiple"
属性,它将起作用.
此外,自从 Woocommerce 3 事情发生了变化:
- 有更好的钩子来保存数据.
- 您现在可以使用 CRUD 对象和相关方法.
以下代码适用于多个产品 ID(产品 ID 数组):
代码位于您的活动子主题(活动主题)的 function.php 文件中.经测试有效.
I have followed this answer How to add more custom field in Linked Product of Woocommerce to add a custom select field to my Linked Product screen in Woocommerce. This new field is meta key is subscription_toggle_product
.
It's working fine, but once you have selected a product, you can't delete it (there is no "Empty" option or cross symbol). I haven't got a clue how I can allow the selection to be deselected. I've tried adding an <option>
with an empty value, but it hasn't worked.
Here is my code:
This kind of select field only works with a defined multiple
attribute and work with an array of values. so you can't use it for a simple ID. If you add to your select field multiple="multiple"
attribute it will work.
Also since Woocommerce 3 things have changed:
- There are better hooks to save the data.
- You can now use CRUD Objects and related methods.
The following code will work for multiple product IDs (an array of products IDs):
Code goes in function.php file of your active child theme (active theme). Tested and works.
这篇关于在 Woocommerce 中添加自定义多选字段以管理产品选项设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!