當我搜索和閱讀以完全提取產品資料時,我必須使用 Json,但我不知道該怎么做,有什么想法嗎?我有這個代碼它不起作用
<?php
add_action( 'woocommerce_before_cart', 'bbloomer_echo_product_ids' );
function bbloomer_echo_product_ids() {
$all_ids = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
) );
foreach ( $all_ids as $id ) {
echo $id;
}
}
?>
uj5u.com熱心網友回復:
嘗試這個...
$args = array(
'post_type' => 'product',
'posts_per_page' => 10,
'product_cat' => 'hoodies'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
echo '<br /><a href="'.get_permalink().'">' . woocommerce_get_product_thumbnail().' '.get_the_title().'</a>';
endwhile;
wp_reset_query();
有一個很好的檔案可以從這里的產品中獲取所有資料 https://www.businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-product-object/
uj5u.com熱心網友回復:
嘗試使用 wp 'init' 操作添加它,只是為了在每個頁面上顯示它。您使用的掛鉤僅顯示在購物車頂部。根據您的主題,可能未使用掛鉤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/371489.html
標籤:php json WordPress的 求购
