小编Fel*_*ato的帖子

管理产品页面自定义字段显示在购物车和结帐中

我已经在产品页面的常规设置选项卡上的WooCommerce Admin中创建了自定义字段,以便为制造插入一些天.我想在每个产品名称上方的购物车和结帐页面上显示此自定义字段值.

这是我的代码:

// Insert a Custom Admin Field
function woo_add_custom_general_fields() {

    echo '<div class="options_group">';

    woocommerce_wp_text_input( array( 
        'id'                => 'days_manufacture', 
        'label'             => __( 'Days for Manufacture', 'woocommerce' ), 
        'placeholder'       => '', 
        'description'       => __( 'Insert here', 'woocommerce' ),
        'type'              => 'number', 
        'custom_attributes' => 
        array(
            'step'  => 'any',
            'min'   => '1'
        ) 
    ) );
    echo '</div>';
}
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );


// Save field
function woo_add_custom_general_fields_save( $post_id ){
    $woocommerce_number_field = $_POST['days_manufacture'];
    if( !empty( $woocommerce_number_field ) )
        update_post_meta( $post_id, 'days_manufacture', esc_attr( $woocommerce_number_field …
Run Code Online (Sandbox Code Playgroud)

php wordpress product custom-fields woocommerce

5
推荐指数
1
解决办法
742
查看次数

标签 统计

custom-fields ×1

php ×1

product ×1

woocommerce ×1

wordpress ×1