php sku添加,php – 在单个产品页面中显示SKU下的自定义字段值

我正在定制WooCommerce,我想在产品页面中添加和显示自定义文本(条件和品牌).

该头寸位于“库存”或“SKU”元下.我已设法创建并保存自定义字段,但如何将这些元值打印到产品页面.

请帮忙!

这是我在functions.php中的代码:

// Display Fields

add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );

// Text Field

function woo_add_custom_general_fields() {

global $woocommerce, $post;

echo '

';

woocommerce_wp_text_input(

array(

'id' => '_conditions',

'label' => __( 'Conditions', 'woocommerce' ),

'placeholder' => 'i.e: brand-new; refurbished; defected...',

'desc_tip' => 'true',

'description' => __( 'Enter the conditions of the products here.', 'woocommerce' )

)

);

echo '

';

woocommerce_wp_text_input(

array(

'id' => '_bands',

'label' => __( 'Brands', 'woocommerce' ),

'placeholder' => 'i.e: Lacoste; Hugo Boss...etc',

'desc_tip' => 'true',

'description' => __( 'Enter names of the Brands of the products if any.', 'woocommerce' )

)

);

}

// Save Fields

add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );

谢谢

解决方法:

您的问题中提供的代码不完整,应该是这样的:

// Enabling and Displaying Fields in backend

add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );

function woo_add_custom_general_fields() {

global $woocommerce, $post;

echo '

';

woocommerce_wp_text_input( array( // Text Field type

'id' => '_conditions',

'label' => __( 'Conditions', 'woocommerce' ),

'placeholder' => 'i.e: brand-new; refurbished; defected...',

'desc_tip' => 'true',

'description' => __( 'Enter the conditions of the products here.', 'woocommerce' )

) );

woocommerce_wp_text_input( array( // Text Field type

'id' => '_brands', // ===> NOT '_bands'

'label' => __( 'Brands', 'woocommerce' ),

'placeholder' => 'i.e: Lacoste; Hugo Boss...etc',

'desc_tip' => 'true',

'description' => __( 'Enter names of the Brands of the products if any.', 'woocommerce' )

));

echo '

'; // Closing
tag HERE
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值