我已经使用这个优秀的教程将自定义字段添加到Woocommerce/Add Product/General选项卡http://www.remicorson.com/mastering-woocommerce-products-custom-fields/
自定义字段(高度,宽度,乘数)正在保存到数据库中.
我想根据自定义字段计算价格,并将价格作为常规价格保存到数据库中.问题是价格没有得到保存.
这是我的代码,来自我的子主题中的functions.php:
/* CUSTOM FIELDS: Add custom fields to Product/General pane in Woocommerce
from http://www.remicorson.com/mastering-woocommerce-products-custom-fields/ */
// 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">';
// Product Height
woocommerce_wp_text_input(
array(
'id' => '_product_height',
'label' => __('Product Height (inches)', 'woocommerce'),
'placeholder' => '',
'description' => __('Enter the product height in inches here.', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
) …Run Code Online (Sandbox Code Playgroud)