[英]How to get all products from current WooCommerce product category?
[英]Get current product category all products parent sku's and display them in array - Woocommerce
我正在嘗試獲取當前類別中的所有產品 sku。 到目前為止,我有這個代碼,它只讓我得到 ID。 我也嘗試過使用meta_query
但出現了一些錯誤。 我對門戶網站和其他網站進行了一些研究,但我根本沒有得到它。 我需要做的是在 all_ids 數組中顯示所有當前的 Woocommerce 產品類別產品父 sku。
到目前為止的代碼
$all_ids = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'tenisky',
'operator' => 'IN',
)
),
) );
輸出將數據導入到我的 HTML 數據層中。
<?php echo "'" . implode ( "', '", $all_ids ) . "'"; ?>
先感謝您!
我認為你應該能夠使用get_post_meta
解決這個問題:
$all_ids = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'tenisky',
'operator' => 'IN',
)
),
) );
$idsku = [];
for ($index = 0; $index < count($all_ids); $index++) {
$idsku[$index] = get_post_meta($all_ids[$index], '_sku', true);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.