Ich habe einen WooCommerce-Shop, der variable Produkte enthält.WooCommerce Alle Produkte mit Variationen anzeigen
Ich möchte eine Art Export (auf einer Seite) erstellen, die mir alle Produkte einschließlich Variationen in einer Tabelle zeigt.
Ich sehe alle Produkte und erstellt eine Schleife, um die Variationen zu erhalten, aber es zeigt mir nur eine Produktvariante.
<?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;
?>
Kann mir jemand sagen, wie man alle Variationen für alle Produkte bekommt?
M.
Vielen Dank. Mein aktuelles Problem ist jedoch, dass es nur ein Produkt zeigt und nicht die anderen ... Irgendwelche Gedanken? – Interactive
Es gefunden. Ich habe die 'Die;' am Ende entfernt, damit die Schleife nicht enden würde. Ich danke dir sehr!!! – Interactive
Ich habe festgestellt, dass das '$ variations' Array ein anderes Array enthält. Soll ich eine andere Schleife benutzen? Das ist das Array: '[0] => Array ([Attribute] => Array ([Attribut_Pa_Größen] => Smallmedium [Attribut_Pa_Farbe] => Grün) [Image_Src] =>' – Interactive