【发布时间】:2015-07-12 14:30:30
【问题描述】:
我需要帮助将自定义字段添加到我的产品变体和简单产品页面。我尝试使用 RemiCorson 的信息 (http://www.remicorson.com/woocommerce-custom-fields-for-variations/),但我不断收到错误消息。我试图复制我在this user's posts for ISBN 中看到的内容,但它对我不起作用。
以下代码的问题是它没有显示在实时站点上。非常感谢所有帮助,我今天大部分时间都在试图找出我做错了什么。
向 Woocommerce 中的简单产品和可变产品页面添加 6 个自定义文本字段和 1 个复选框。这些不是由购物者提供(即填写)的字段,而是我希望在我的产品页面上(而不是在标签内)显示的自定义信息。
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Custom fields will be created here...
// Text Field
woocommerce_wp_text_input(
array(
'id' => '_ISBN_field',
'label' => __( 'ISBN', 'woocommerce' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'ISBN.', 'woocommerce' )
)
);
function woo_add_custom_general_fields_save( $post_id ){
// Customer text ISBN Field
$woocommerce_text_field = $_POST['_ISBN_field'];
if( !empty( $woocommerce_text_field ) )
update_post_meta( $post_id, '_ISBN_field', esc_attr( $woocommerce_text_field ) );
else
update_post_meta( $post_id, '_ISBN_field', '' );
}
// Display Custom Field Value
echo get_post_meta( $post->ID, '_ISBN_field', true );
}
/* WooCommerce */
/* ----------------------------------------------------------------------------------- */
/* Start WooThemes Functions - Please refrain from editing this section */
/* ----------------------------------------------------------------------------------- */
【问题讨论】:
-
Remi 的代码有什么错误?
标签: php wordpress woocommerce