WooCommerce מלאי אזל בווריאציה

רוני רביץ

משתמש סופר מקצוען
D I G I T A L
אני מעוניין שיהיה כתוב המלאי אזל בבחירת ווריאציה,
כלומר שזה יהיה כתוב כבר בבחירה ולא רק אחרי שבוחרים,
הנה דוגמא,
מישהו יודע איך אני עושה את זה?
 

נוכחות

מהמשתמשים המובילים!
מנוי פרימיום
עיצוב גרפי
עימוד ספרים
עריכה תורנית
D I G I T A L
יוצרי ai
אולי תנסה את זה.
קוד:
add_filter( 'woocommerce_variation_option_name',
'customizing_variations_terms_name', 10, 1 );
function customizing_variations_terms_name( $term_name ){

if(is_admin())
    return $term_name;

global $product;
$second_loop_stoped = false;

// Get available product variations
$product_variations = $product->get_available_variations();

// Iterating through each available product variation
foreach($product_variations as $variation){

    $variation_id = $variation['variation_id'];
    $variation_obj = new WC_Product_Variation( $variation_id );

    ## WOOCOMMERCE RETRO COMPATIBILITY ##
    if ( version_compare( WC_VERSION, '3.0', '<' ) ) # BEFORE Version 3 (older)
    {
        $stock_status = $variation_obj->stock_status;
        $stock_qty = intval($variation_obj->stock);

        // The attributes WC slug key and slug value for this variation
        $attributes_arr = $variation_obj->get_variation_attributes();
    }
    else # For newest verions: 3.0+ (and Up)
    {
        $stock_status = $variation_obj->get_stock_status();
        $stock_qty = $variation_obj->get_stock_quantity();

        // The attributes taxonomy key and slug value for this variation
        $attributes_arr = $variation_obj->get_attributes();
    }

    if(count($attributes_arr) != 1) // Works only for 1 attribute set in the product
        return $term_name;

    // Get the terms for this attribute
    foreach( $attributes_arr as $attr_key => $term_slug){
        // Get the attribute taxonomy
        $term_key = str_replace('attribute_', '', $attr_key );

        // get the corresponding term object
        $term_obj = get_term_by( 'slug', $term_slug, $term_key );
        if( $term_obj->name == $term_name ){ // If the term name matches we stop the loops
            $second_loop_stoped = true;
            break;
        }
    }
    if($second_loop_stoped)
        break;
}
if( $stock_qty>0 )
    return $term_name .= ' - ' . $stock_status . ' ('.$stock_qty.')';
else
    return $term_name .= ' - ' . $stock_status;

}

מכאן
 

.A.B.

משתמש מקצוען
מנוי פרימיום
עיצוב גרפי
D I G I T A L
יוצרי ai
היי מקפיצה,
אשמח לדעת אם יש תוסף לזה.
ואם כן אם הוא טוב למוצר בודד וובילדר של ג'ט.
תודה
 

MyHost

משתמש פעיל
D I G I T A L
אולי תנסה את זה.
קוד:
add_filter( 'woocommerce_variation_option_name',
'customizing_variations_terms_name', 10, 1 );
function customizing_variations_terms_name( $term_name ){

if(is_admin())
    return $term_name;

global $product;
$second_loop_stoped = false;

// Get available product variations
$product_variations = $product->get_available_variations();

// Iterating through each available product variation
foreach($product_variations as $variation){

    $variation_id = $variation['variation_id'];
    $variation_obj = new WC_Product_Variation( $variation_id );

    ## WOOCOMMERCE RETRO COMPATIBILITY ##
    if ( version_compare( WC_VERSION, '3.0', '<' ) ) # BEFORE Version 3 (older)
    {
        $stock_status = $variation_obj->stock_status;
        $stock_qty = intval($variation_obj->stock);

        // The attributes WC slug key and slug value for this variation
        $attributes_arr = $variation_obj->get_variation_attributes();
    }
    else # For newest verions: 3.0+ (and Up)
    {
        $stock_status = $variation_obj->get_stock_status();
        $stock_qty = $variation_obj->get_stock_quantity();

        // The attributes taxonomy key and slug value for this variation
        $attributes_arr = $variation_obj->get_attributes();
    }

    if(count($attributes_arr) != 1) // Works only for 1 attribute set in the product
        return $term_name;

    // Get the terms for this attribute
    foreach( $attributes_arr as $attr_key => $term_slug){
        // Get the attribute taxonomy
        $term_key = str_replace('attribute_', '', $attr_key );

        // get the corresponding term object
        $term_obj = get_term_by( 'slug', $term_slug, $term_key );
        if( $term_obj->name == $term_name ){ // If the term name matches we stop the loops
            $second_loop_stoped = true;
            break;
        }
    }
    if($second_loop_stoped)
        break;
}
if( $stock_qty>0 )
    return $term_name .= ' - ' . $stock_status . ' ('.$stock_qty.')';
else
    return $term_name .= ' - ' . $stock_status;

}

מכאן
על פניו נראה כי הקוד יעבוד בfunction.php של התבנית בה את משתמש.
אך תמיד מומלץ לבצע שינויי קוד בליווי מתכנת PHP למקרה ויקרוס האתר או באם ידרש שינויים או התאמות נוספות.

בברכה,
דין MyHost.
 

.A.B.

משתמש מקצוען
מנוי פרימיום
עיצוב גרפי
D I G I T A L
יוצרי ai
אני מעדיפה תוסף מאשר קוד
 

אולי מעניין אותך גם...

הפרק היומי

הפרק היומי! כל ערב פרק תהילים חדש. הצטרפו אלינו לקריאת תהילים משותפת!


תהילים פרק קכב

א שִׁיר הַמַּעֲלוֹת לְדָוִד שָׂמַחְתִּי בְּאֹמְרִים לִי בֵּית יְהוָה נֵלֵךְ:ב עֹמְדוֹת הָיוּ רַגְלֵינוּ בִּשְׁעָרַיִךְ יְרוּשָׁלִָם:ג יְרוּשָׁלִַם הַבְּנוּיָה כְּעִיר שֶׁחֻבְּרָה לָּהּ יַחְדָּו:ד שֶׁשָּׁם עָלוּ שְׁבָטִים שִׁבְטֵי יָהּ עֵדוּת לְיִשְׂרָאֵל לְהֹדוֹת לְשֵׁם יְהוָה:ה כִּי שָׁמָּה יָשְׁבוּ כִסְאוֹת לְמִשְׁפָּט כִּסְאוֹת לְבֵית דָּוִיד:ו שַׁאֲלוּ שְׁלוֹם יְרוּשָׁלִָם יִשְׁלָיוּ אֹהֲבָיִךְ:ז יְהִי שָׁלוֹם בְּחֵילֵךְ שַׁלְוָה בְּאַרְמְנוֹתָיִךְ:ח לְמַעַן אַחַי וְרֵעָי אֲדַבְּרָה נָּא שָׁלוֹם בָּךְ:ט לְמַעַן בֵּית יְהוָה אֱלֹהֵינוּ אֲבַקְשָׁה טוֹב לָךְ:
נקרא  2  פעמים

לוח מודעות

למעלה