【发布时间】:2016-12-23 22:39:21
【问题描述】:
我正在自定义 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 '<div class="options_group">';
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 '</div>';
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' );
谢谢
【问题讨论】:
标签: php wordpress woocommerce custom-fields product