मैं Woocommerce करने के लिए कस्टम फ़ील्ड जोड़ लिया है/उत्पाद/सामान्य टैब इस उत्कृष्ट ट्यूटोरियल http://www.remicorson.com/mastering-woocommerce-products-custom-fields/woocommerce calculate और बचाने के मूल्य
कस्टम फ़ील्ड (ऊंचाई, चौड़ाई, गुणक) डेटाबेस ठीक करने के लिए सहेजा जा रहा है का उपयोग कर जोड़ें। मैं कस्टम फ़ील्ड के आधार पर मूल्य की गणना करना चाहता हूं, और कीमत को डेटाबेस में नियमित मूल्य के रूप में सहेजना चाहता हूं। समस्या यह है कि कीमत सहेजा नहीं जा रहा है।
यहाँ मेरे बच्चे विषय में 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'
)
)
);
// Product Width
woocommerce_wp_text_input(
array(
'id' => '_product_width',
'label' => __('Product Width (inches)', 'woocommerce'),
'placeholder' => '',
'description' => __('Enter the product width in inches here.', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
)
);
// Product Area Multiplier
woocommerce_wp_text_input(
array(
'id' => '_product_area_mult',
'label' => __('Product Area Multiplier', 'woocommerce'),
'placeholder' => '',
'description' => __('Enter Product Area Multiplier. ', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
)
);
// Product Area Price: added this field to check if this value is being calculated
woocommerce_wp_text_input(
array(
'id' => '_product_area_price',
'label' => __('Product Area Price', 'woocommerce'),
'placeholder' => '',
'description' => __('Product Area Price. Calculated automatically', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
)
);
echo '</div>';
}
function woo_add_custom_general_fields_save($post_id)
{
$woocommerce_product_height = $_POST['_product_height'];
$woocommerce_product_width = $_POST['_product_width'];
$woocommerce_product_area_mult = $_POST['_product_area_mult'];
$woocommerce_product_area_price = $_POST['_product_area_price'];
// save height, width, multiplier
if (!empty($woocommerce_product_height))
update_post_meta($post_id, '_product_height', esc_attr($woocommerce_product_height));
if (!empty($woocommerce_product_width))
update_post_meta($post_id, '_product_width', esc_attr($woocommerce_product_width));
if (!empty($woocommerce_product_area_mult))
update_post_meta($post_id, '_product_area_mult', esc_attr($woocommerce_product_area_mult));
// calculate and save _product_area_price, _regular_price, price as Height*Width*Mult
if (!empty($woocommerce_product_height) && !empty($woocommerce_product_width) && !empty($woocommerce_product_area_mult))
$woocommerce_product_area_price = $woocommerce_product_height * $woocommerce_product_width * $woocommerce_product_area_mult;
if (!empty($woocommerce_product_area_price))
update_post_meta($post_id, '_product_area_price', esc_attr($woocommerce_product_area_price));
if (!empty($woocommerce_product_area_price))
{
update_post_meta($post_id, '_regular_price', esc_attr($woocommerce_product_area_price));
update_post_meta($post_id, '_price', esc_attr($woocommerce_product_area_price));
}
}
सब कुछ डेटाबेस में कीमत क्षेत्रों को अद्यतन करने को छोड़कर काम कर रहा है। मेरे कस्टम फ़ील्ड एक ही वाक्यविन्यास के साथ अद्यतन कर रहे हैं। मैंने पुष्टि की है कि परिवर्तनीय $woocommerce_product_area_price
मौजूद है, और यह कस्टम फ़ील्ड अपडेट कर रहा है, लेकिन वही चर _regular_price
या _price
फ़ील्ड अपडेट नहीं कर रहा है। तो इन पंक्तियों के काम नहीं कर रहे हैं, भले ही एक ही चर _product_area_price
फ़ील्ड अपडेट होगा:
if (!empty($woocommerce_product_area_price))
{
update_post_meta($post_id, '_regular_price', esc_attr($woocommerce_product_area_price));
update_post_meta($post_id, '_price', esc_attr($woocommerce_product_area_price));
}
हो सकता है कि वहाँ कुछ वाक्य रचना है या जाँच Woocommerce में कीमत अद्यतन करने के लिए मुझे याद आ रही?
क्या आपने डीबी में चेक किया है कि कीमत बचाई जा रही है या नहीं? या आप समस्या यह है कि यह फ्रंटेंड में परिलक्षित नहीं हो रहा है? –
डेटाबेस, राउनाक में सहेजा नहीं जा रहा है। – Norv