تابع ووکامرسی wc_get_formatted_variation فرمت ویژگی های متغیر محصول

تابع ووکامرسی wc_get_formatted_variation فرمت ویژگی های متغیر محصول

تابع ووکامرسی wc_get_formatted_variation – فرمت ویژگی های متغیر محصول

Syntax – سینتکس

(string) wc_get_formatted_variation( (array|WC_Product_Variation) $variation, (constant) $flat = false, (bool) $include_names = true ); 

Parameters – پارامتر ها (3)

  • 1- $variation (array|WC_Product_Variation)
  • 2- $flat (constant)
  • 3- $include_names (bool)

Usage – نحوه استفاده

if ( !function_exists( 'wc_get_formatted_variation' ) ) { 
    require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; 
} 
  
// The variation. 
$variation = null; 
  
// (default: false) 
$flat = false; 
  
// include attribute names/labels 
$include_names = true; 
  
// NOTICE! Understand what this does before running. 
$result = wc_get_formatted_variation($variation, $flat, $include_names); 
    

Defined – محل تعریف

/includes/wc-product-functions.php

function wc_get_formatted_variation( $variation, $flat = false, $include_names = true ) { 
    $return = ''; 
 
    if ( is_a( $variation, 'WC_Product_Variation' ) ) { 
        $variation_attributes = $variation->get_attributes(); 
        $product = $variation; 
    } else { 
        $product = false; 
        // Remove attribute_ prefix from names. 
        $variation_attributes = array(); 
        if ( is_array( $variation ) ) { 
            foreach ( $variation as $key => $value ) { 
                $variation_attributes[ str_replace( 'attribute_', '', $key ) ] = $value; 
            } 
        } 
    } 
 
    $list_type = $include_names ? 'dl' : 'ul'; 
 
    if ( is_array( $variation_attributes ) ) { 
 
        if ( ! $flat ) { 
            $return = '<' . $list_type . ' class="variation">'; 
        } 
 
        $variation_list = array(); 
 
        foreach ( $variation_attributes as $name => $value ) { 
            if ( ! $value ) { 
                continue; 
            } 
 
            // If this is a term slug, get the term's nice name 
            if ( taxonomy_exists( $name ) ) { 
                $term = get_term_by( 'slug', $value, $name ); 
                if ( ! is_wp_error( $term ) && ! empty( $term->name ) ) { 
                    $value = $term->name; 
                } 
            } else { 
                $value = ucwords( str_replace( '-', ' ', $value ) ); 
            } 
 
            if ( $include_names ) { 
                if ( $flat ) { 
                    $variation_list[] = wc_attribute_label( $name, $product ) . ': ' . rawurldecode( $value ); 
                } else { 
                    $variation_list[] = '
' . wc_attribute_label( $name, $product ) . ':
' . rawurldecode( $value ) . '
'; } } else { if ( $flat ) { $variation_list[] = rawurldecode( $value ); } else { $variation_list[] = '
  • ' . rawurldecode( $value ) . '
  • '; } } } if ( $flat ) { $return .= implode( ', ', $variation_list ); } else { $return .= implode( '', $variation_list ); } if ( ! $flat ) { $return .= ''; } } return $return; }

    versions – نسخه ها

    از نسخه : 3.0.2

    نسخه فعلی : 3.0.6

    دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2

    ارسال نظر

    جهت استفاده از کد حتما از تگ pre استفاده نمایید .

    contact us