Php 如何将产品表列表更改为使用变量名而不是变量slug

Php 如何将产品表列表更改为使用变量名而不是变量slug,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我偶然发现了一个非常酷的woocommerce剪报,我想通过将它输入到我的function.php页面,将其整合到我的站点中。我现在已经这么做了,但问题是woocommerce现在从变量产品中提取变量slug,并将其显示在站点前端 有没有一种方法可以让我更改下面的代码,使用变量的实际名称而不是slug 这是下面的代码 /*product variations list table*/ function find_valid_variations() { global $product; $va

我偶然发现了一个非常酷的woocommerce剪报,我想通过将它输入到我的function.php页面,将其整合到我的站点中。我现在已经这么做了,但问题是woocommerce现在从变量产品中提取变量slug,并将其显示在站点前端

有没有一种方法可以让我更改下面的代码,使用变量的实际名称而不是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;}

感谢大家分享您的知识。

当我们得到产品变体slug时,我们可以得到它的名称如下:

参考链接:

请检查代码和行号,80到91

在这里,我们可以直接提取变体名称。(第86行)至


$woomerce->attribute_label

非常感谢您的帮助。