2014-07-17 21 views
3

我已经偶然发现了一个非常酷的woocommerce剪辑,我想通过将其输入到我的function.php页面中来将其合并到我的网站中。我现在所做的,但问题是woocommerce现在从变量产品中抽取变量slug并将其显示在网站的前端。如何更改woocommerce剪切使用变量名称而不是产品表列表的变量slu 012

有没有办法可以改变下面的代码来使用给变量而不是slug的实际名称?

这里是波纹管

/*product variations list table*/ 
function find_valid_variations() { 
global $product; 

$variations = $product->get_available_variations(); 
$attributes = $product->get_attributes(); 
$new_variants = array(); 

// Loop through all variations 
foreach($variations as $variation) { 

    // Peruse the attributes. 

    // 1. If both are explicitly set, this is a valid variation 
    // 2. If one is not set, that means any, and we must 'create' the rest. 

    $valid = true; // so far 
    foreach($attributes as $slug => $args) { 
     if(array_key_exists("attribute_$slug", $variation['attributes']) && !empty($variation['attributes']["attribute_$slug"])) { 
      // Exists 

     } else { 
      // Not exists, create 
      $valid = false; // it contains 'anys' 
      // loop through all options for the 'ANY' attribute, and add each 
      foreach(explode('|', $attributes[$slug]['value']) as $attribute) { 
       $attribute = trim($attribute); 
       $new_variant = $variation; 
       $new_variant['attributes']["attribute_$slug"] = $attribute; 
       $new_variants[] = $new_variant; 
      } 

     } 
    } 

    // This contains ALL set attributes, and is itself a 'valid' variation. 
    if($valid) 
     $new_variants[] = $variation; 

} 

return $new_variants;} 

感谢您分享您的knowladge家伙的代码。

回答

3

当我们变,变型产品一决高下,我们可以按照如下得到它的名字,

Refernece链接:https://gist.github.com/renegadesk/3967956

请检查代码行不行,80至91

这里,我们可以直接提取变体名称。 (Line no。86)通过,

$ woocommerce-> attribute_label

+0

非常感谢你我感谢你给我的所有帮助。 – user2747487