簡體   English   中英

表中的woocommerce產品變體標題

[英]woocommerce product variation title in table

我想在表格的單個產品頁面中列出我的產品變體及其尺寸,尺寸部分一切正常,但我無法顯示變體名稱。 這是我的代碼:

<?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>

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

另外,我有95%的肯定您將要使用類方法而不是直接訪問對象屬性會在WooCommerce 2.7中引起錯誤/警告。 另外,它通常通過過濾器運行,以防任何插件都針對該值。 (例如:使用$variation->get_price()代替$variation->price

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM