表中的woocommerce产品变体标题

时间:2016-12-20 16:15:37

标签: php wordpress woocommerce product variations

我想在单个产品页面中列出我的产品变体,并在尺寸表中列出一切,但我无法获得要显示的变体名称。这是我的代码:

<?php 

    $variations = $product->get_available_variations();
    foreach ( $variations as $variable_array ){
    $variation = new WC_Product( $variable_array['variation_id'] );?>
    <tr>                                

        <td>
            <b>here I need the variation title</b>
        </td>                           
            <?php
                $magassag = $variation->height;
                ?>
                <?php if ($magassag != 0) {
                echo '<td class="cell_magas">' . $variation->height . ' cm' . '</td>'; }
                else{
                ?>
                <style type="text/css">#magassag-cim{display:none;}</style>
            <?php } ?>                      
            <?php
                $atmero = $variation->width;
                ?>
                <?php if ($atmero != 0) {
                echo '<td class="cell_szell">' . $variation->width . ' cm' . '</td>'; }
                else{
                ?>
                <style type="text/css">#szellesseg-cim{display:none;}</style>
            <?php } ?>      
            <?php
                $szellesseg = $variation->length;
                ?>
                <?php if ($szellesseg != 0) {
                echo '<td class="cell_latime">' . $variation->length . ' cm' . '</td>'; }
                else{
                ?>
                <style type="text/css">#szellesseg-cim{display:none;}</style>
            <?php } ?>          
        <td>
            <?php echo $variation->price;?>
        </td>
    </tr>

1 个答案:

答案 0 :(得分:4)

您可以使用$variation->get_formatted_name()$variation->get_title()

另外,我95%肯定你会想要使用类方法而不是直接访问对象属性会导致WooCommerce 2.7中出现错误/警告。此外,它通常通过过滤器运行,以防任何插件针对该值。 (例如:使用$variation->get_price()代替$variation->price

相关问题