تابع ووکامرسی wc_attribute_label دریافت برچسب های ویژگی محصول

تابع ووکامرسی wc_attribute_label دریافت برچسب های ویژگی محصول

تابع ووکامرسی wc_attribute_label – نحوه دریافت کردن برچسب های ویژگی محصول

Syntax – سینتکس

(string) wc_attribute_label( (string) $name, (string) $product = '' ); 

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

  • 1- $name (string)
  • 2- $product (string)

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

if ( !function_exists( 'wc_attribute_label' ) ) { 
    require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-attribute-functions.php'; 
} 
  
// The name. 
$name = ''; 
  
// object Optional 
$product = ''; 
  
// NOTICE! Understand what this does before running. 
$result = wc_attribute_label($name, $product); 
    

Defined – محل تعریف

/includes/wc-attribute-functions.php

function wc_attribute_label( $name, $product = '' ) { 
    global $wpdb; 
 
    if ( taxonomy_is_product_attribute( $name ) ) { 
        $name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $name ) ); 
        $all_labels = wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name' ); 
        $label = isset( $all_labels[ $name ] ) ? $all_labels[ $name ] : $name; 
    } elseif ( $product ) { 
        if ( $product->is_type( 'variation' ) ) { 
            $product = wc_get_product( $product->get_parent_id() ); 
        } 
        // Attempt to get label from product, as entered by the user. 
        if ( ( $attributes = $product->get_attributes() ) && isset( $attributes[ sanitize_title( $name ) ] ) ) { 
            $label = $attributes[ sanitize_title( $name ) ]->get_name(); 
        } else { 
            $label = $name; 
        } 
    } else { 
        $label = $name; 
    } 
 
    return apply_filters( 'woocommerce_attribute_label', $label, $name, $product ); 
} 

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