国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

如何限制woocommerce客戶(hù)範(fàn)本中的產(chǎn)品屬性
P粉191323236
P粉191323236 2023-09-07 19:42:32
0
1
701

我可以透過(guò)在表格行中選擇的自訂屬性名稱(chēng)(如「顏色」、「尺寸」、「重量」等)來(lái)取得屬性,但我只想顯示 3 行。 我的工作程式碼如下,但它顯示了所有程式碼,我只想顯示 3 行

add_action( 'cw_shop_page_attribute', 'cw_shop_page_attribute', 25 );

function cw_shop_page_attribute() {
global $product;
$display_size = $product->get_attribute('display-size');
$processor = $product->get_attribute('processor-type');
$rearcamera = $product->get_attribute('primary-camera');
$frontcamera = $product->get_attribute('secondary-camera');
$storage = $product->get_attribute('internal-storage-gb');
$m_ram = $product->get_attribute('ram-gb');
$frontcamera = $product->get_attribute('secondary-camera');

if ( $display_size ) {
    echo'<tr class="_plspcdt"><td class="_plspcicon"><i class="fa fa-desktop fa-2x"></i></td><td class="_atrbttl">Display</td>';
    echo'<td class="_atrbvlu">'; printf ($display_size);
    echo'</td></tr>';
   }
if ( $processor ) {
    echo'<tr class="_plspcdt"><td class="_plspcicon"><i class="fa fa-microchip fa-2x"></i></td><td class="_atrbttl">Processor</td>';
    echo'<td class="_atrbvlu">'; printf ($processor);
    echo'</td></tr>';
   }
if ( $rearcamera ) {
    echo'<tr class="_plspcdt"><td class="_plspcicon"><i class="fa fa-camera fa-2x"></i></td><td class="_atrbttl">Rear Camera</td>';
    echo'<td class="_atrbvlu">'; printf ($rearcamera);
    echo'</td></tr>';
   }  
if ( $frontcamera ) {
    echo'<tr class="_plspcdt"><td class="_plspcicon"><i class="fa fa-camera fa-2x"></i></td><td class="_atrbttl">Front Camera</td>';
    echo'<td class="_atrbvlu">'; printf ($frontcamera);
    echo'</td></tr>';
   }

如何僅顯示其中的 3 行並在為空時(shí)隱藏

P粉191323236
P粉191323236

全部回覆(1)
P粉691958181

get_attribute () 傳回以逗號(hào)分隔的值字串,因此您可以使用 php 的explode 函數(shù)以陣列形式循環(huán)遍歷這些值,然後在傳回 3 個(gè)結(jié)果後退出。

例如:

if ( $display_size ) {
    echo'<tr class="_plspcdt"><td class="_plspcicon"><i class="fa fa-desktop fa-2x"></i></td><td class="_atrbttl">Display</td>';
    $display_size_array = explode( ',', $display_size );
    $count = 0;
    foreach ( $display_size_array as $attribute ) {
        if ( $count >= 3 ) {
            break;
        }
        echo'<td class="_atrbvlu">' . $attribute . '</td';
        $count++;
    }
    echo'></tr>';
}
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板