2017-07-20 82 views

回答

0

我想創建一個自定義的循環是這樣的:

https://www.philowen.co/blog/show-latest-woocommerce-products-in-your-template/

要麼將​​其創建爲不同的地方你的計劃來完成這一個自定義簡碼或行動,並在使用中的產品類拉到屬性循環:

<?php 
$product = new WC_Product; 
$attributes = $product->get_attributes(); 

foreach loop... 

?> 

喜歡的東西:

<?php 
$args = array(
'post_type' => 'product', 
'stock' => 1, 
'posts_per_page' => 4, 
'orderby' =>'date', 
'order' => 'DESC'); 
$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); ?> 
global $product; 
    // Get the attibutes 
    $attributes = $product->get_attributes(); 

    // Loop and display the value 
    // var_dump $attributes to see what you can output 
    foreach ($attributes as $attribute) { 
      echo $attribute['value']; 
    } 

<?php endwhile; ?> 
<?php wp_reset_query(); ?> 
+0

謝謝,這在一定程度上有所幫助。鏈接中的解決方案僅向我顯示如何顯示圖像,標題和價格。我仍然對如何訪問woocommerce產品的其他屬性感到困惑,例如如果我賣車,我想在最近的產品部分顯示里程數。 –

+0

嘗試類似上面的內容,讓我知道如果你得到任何錯誤和var_dump。 – Max