0
我使用Woocommerce插件的近期產品簡碼,它會返回產品圖片,標題和價格。我所有的產品都有更多屬性,我希望能夠返回。我怎樣才能做到這一點?woocommerce近期產品短代碼如何編輯以便返回產品屬性?
我使用Woocommerce插件的近期產品簡碼,它會返回產品圖片,標題和價格。我所有的產品都有更多屬性,我希望能夠返回。我怎樣才能做到這一點?woocommerce近期產品短代碼如何編輯以便返回產品屬性?
我想創建一個自定義的循環是這樣的:
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(); ?>
謝謝,這在一定程度上有所幫助。鏈接中的解決方案僅向我顯示如何顯示圖像,標題和價格。我仍然對如何訪問woocommerce產品的其他屬性感到困惑,例如如果我賣車,我想在最近的產品部分顯示里程數。 –
嘗試類似上面的內容,讓我知道如果你得到任何錯誤和var_dump。 – Max