मैं अपने अधिकांश उत्पादों पर काम करने वाले विवरण के बाद अपने सभी उत्पादों पर एक संदेश दिखाना चाहता हूं। हालांकि, समस्या यह है कि परिवर्तनीय उत्पादों पर, संदेश उत्पाद के समग्र विवरण और जब एक प्रकार का चयन किया गया था, दोनों पर दिखाई देगा।
इसलिए जब संस्करण चुना जाता है तो मुझे अतिरिक्त टेक्स्ट नहीं चाहिए, इसलिए मैंने अपने फ़ंक्शन में संशोधन किया और एक और कथन जोड़ने के लिए। समारोह अब इस प्रकार है:
add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
global $post;
global $product;
// Don't want the message if the product is in these specific categories
if ( has_term( "training-courses-v2", "product_cat", $post->ID ) || has_term( "online-training-courses", "product_cat", $post->ID ) ) {
return $description;
}
else if ( $product->is_type( 'variation' ) ) {
return $description;
}
else {
$text="<strong>Please note that as this is a hygiene product, only unopened products in their original, unopened condition and in their original packaging are eligible for a refund.</strong>";
return $description.$text;
}
}
हालांकि, यह अभी भी काम नहीं करता है और टेक्स्ट दोनों जगहों पर दिखाई देता है। मैंने उत्पाद प्रकार को परिवर्तनीय होने के लिए भी बदलने की कोशिश की लेकिन फिर संदेश किसी भी स्थान पर प्रकट नहीं होता है।
क्या कोई ऐसा तरीका है जिससे मैं इसे प्राप्त कर सकूं ताकि जब उत्पाद में भिन्नता हो तो संदेश जोड़ा न जाए?
1 उत्तर
एक चर उत्पाद के प्रत्येक रूपांतर विवरण में अपने अतिरिक्त पाठ को जोड़ने से बचने के लिए निम्नलिखित का उपयोग करें:
add_filter( 'woocommerce_short_description', 'ts_add_text_short_descr' );
function ts_add_text_short_descr( $description ){
global $post, $product;
$product_id = is_a($product, 'WC_Product') ? $product->get_id() : get_the_id();
// Don't want the message if the product is in these specific categories
if ( ! has_term( array("training-courses-v2", "online-training-courses"), "product_cat", $product_id ) ) {
$description .= "<strong>Please note that as this is a hygiene product, only unopened products in their original, unopened condition and in their original packaging are eligible for a refund.</strong>";
}
return $description;
}
add_filter( 'woocommerce_available_variation', 'filter_wc_available_variation_desscription', 10, 3);
function filter_wc_available_variation_desscription( $data, $product, $variation ) {
if ( ! has_term( array("training-courses-v2", "online-training-courses"), "product_cat", $product->get_id() ) ) {
$data['variation_description'] = get_post_meta($variation->get_id(), '_variation_description', true);
}
return $data;
}
कोड आपके सक्रिय चाइल्ड थीम (या सक्रिय थीम) के functions.php फ़ाइल में जाता है। परीक्षण किया और काम किया।
संबंधित सवाल
नए सवाल
php
PHP एक व्यापक रूप से उपयोग किया जाता है, उच्च-स्तरीय, गतिशील, वस्तु-उन्मुख, और व्याख्या की गई स्क्रिप्टिंग भाषा मुख्य रूप से सर्वर-साइड वेब विकास के लिए डिज़ाइन की गई है। PHP भाषा के बारे में सवालों के लिए इस्तेमाल किया।