我正在尝试在 Woocommerce 产品变体中创建 4 个多选选项。
例如:我在卖树,想显示树可用的季节。所以我们有 4 个季节(春、夏、秋、冬),有些树有两个或树的季节。
我将此代码添加到我的functions.php,但它不会保存选定的选项。当我保存选项并重新加载页面时,选项再次变为空白。
而且我还想知道如何将单个产品页面(前端)上的选定选项显示为图标。
目前,带有选项的功能适用于产品变体。请参阅此屏幕截图(具有多选选项的产品变体):
我的代码:
// Add Variation Settings
add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
/**
* Create custom field type
*
*/
function woocommerce_wp_select_multiple( $field ) {
global $thepostid, $post, $woocommerce;
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
$field['value'] = …
Run Code Online (Sandbox Code Playgroud)