使WooCommerce中的产品的自定义字段可用于映射

我在WooCommerce中创建了一些自定义产品字段,它们可以正确显示,并且也可以保存数据。

/**
 * Adds Custom Fields for Description,Bullet 1,Bullet 2,Bullet 3,Bullet 4,Bullet 5,Bullet 6,Search Term
*/

// Display Fields
add_action('woocommerce_product_options_advanced','woocommerce_product_custom_fields');
// Save Fields
add_action('woocommerce_process_product_meta','woocommerce_product_custom_fields_save');
function woocommerce_product_custom_fields()
{
    global $woocommerce,$post;
    echo '<div class="product_custom_field">';

    //Custom Product Description
    woocommerce_wp_textarea_input(
        array(
            'id' => '_mkt_product_description','placeholder' => 'Enter the Product Description','label' => __('Market Product Description','woocommerce')
        )
    );

    // Custom Bullet 1 Text Field
    woocommerce_wp_text_input(
        array(
            'id' => '_bullet_1','placeholder' => 'Bullet 1 field','label' => __('Bullet 1','woocommerce'),'desc_tip' => 'true'
        )
    );

    // Custom Bullet 2 Text Field
    woocommerce_wp_text_input(
        array(
            'id' => '_bullet_2','placeholder' => 'Bullet 2 field','label' => __('Bullet 2','desc_tip' => 'true'
        )
    );

    // Custom Bullet 3 Text Field
    woocommerce_wp_text_input(
        array(
            'id' => '_bullet_3','placeholder' => 'Bullet 3 field','label' => __('Bullet 3','desc_tip' => 'true'
        )
    );


    // Custom Bullet 4 Text Field
    woocommerce_wp_text_input(
        array(
            'id' => '_bullet_4','placeholder' => 'Bullet 4 field','label' => __('Bullet 4','desc_tip' => 'true'
        )
    );

    // Custom Bullet 5 Text Field
    woocommerce_wp_text_input(
        array(
            'id' => '_bullet_5','placeholder' => 'Bullet 5 field','label' => __('Bullet 5','desc_tip' => 'true'
        )
    );

    // Custom Bullet 6 Text Field
    woocommerce_wp_text_input(
        array(
            'id' => '_bullet_6','placeholder' => 'Bullet 6 field','label' => __('Bullet 6','desc_tip' => 'true'
        )
    );  

    // Market Search Term
    woocommerce_wp_text_input(
        array(
            'id' => '_search_term','placeholder' => 'Search Term field','label' => __('Search Term','desc_tip' => 'true'
        )
    );      

    echo '</div>';
}

/**
 * End of Adds Custom Fields for Description,Search Term
*/

但是,我无法将这些自定义字段显示在我需要这些值的产品Feed扩展的可用映射选项中。对于此扩展中的映射,我可以看到的唯一可用属性如下: Available Attributes for Mapping

我创建了上面的自定义字段代码,并提供了一些在线参考,并且我对php和hook的了解有限。

我认为我缺少要回显或get_post或get_value的代码,并使这些自定义字段可作为WooCommerce属性映射为管理后端中的WooCommerce属性,例如下面的示例代码

function woocommerce_custom_fields_display()
{
global $post;
$product = wc_get_product($post->ID);
$custom_fields_woocommerce_title = $product->get_meta('woocommerce_custom_fields');
if ($custom_fields_woocommerce_title) {
printf(
'<div><label>%s</label><input type="text" id="woocommerce_product_custom_fields_title" name="woocommerce_product_custom_fields_title" value=""></div>',esc_html($custom_fields_woocommerce_title)
);
}
}
add_action('woocommerce_before_add_to_cart_button','woocommerce_custom_fields_display');

上面是示例代码参考我不需要在产品/购物车/订单/结帐页面上显示这些自定义属性。我只要求它们可用于映射。

任何上述帮助将不胜感激。

cengyicang 回答:使WooCommerce中的产品的自定义字段可用于映射

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3082533.html

大家都在问