0
私は可変商品を保持するWooCommerceショップを持っています。WooCommerceバリエーションのあるすべての商品を表示
テーブル内のバリエーションを含むすべての商品を表示するエクスポートを作成したいと考えています。
私はすべての製品を表示していますが、バリエーションを得るためにループを作成しましたが、1つの製品バリエーションしか表示されません。
<?php
/*
Template Name: Store Management
*/
if (!is_user_logged_in() || !current_user_can('manage_options')) wp_die('This page is private.');
// Get
$args = array(
'post_type' => 'product',
'numberposts' => -1,
);
$products = get_posts($args);
echo '<pre>';
print_r($products);
echo '</pre>';
foreach($products as $product):
$args = array(
'post_parent' => $plan->ID,
'post_type' => 'product_variation',
'numberposts' => -1,
);
$product = wc_get_product($product->ID);
$variations = $product->get_available_variations();
echo '<pre>';
print_r($variations);
echo '</pre>';
endforeach;
?>
すべてのバリエーションをすべての製品に適用する方法を教えてもらえますか?
M.
ありがとうございます。しかし、私の現在の問題は、それは1つの製品だけを表示し、他の製品は表示しないということです。 – Interactive
見つけました。最後にループが終了しないように 'die ;;'を削除しました。どうもありがとうございます!!! – Interactive
'$ variations'配列は別の配列を保持しています。別のループを使うべきですか?これは配列です: '[0] => Array([attribute] => Array([attribute_pa_sizes] => smallmedium [attribute_pa_color] => green)[image_src] => – Interactive