Error in wc_get_products
caught by @SallyCJ fixed my problem.
Where I had ingredients
, I needed pa_ingredients
.
Working code is as follows:
$taxonomy = 'pa_ingredients';
$terms = get_terms( $taxonomy );
foreach ( $terms as $term ) {
$products = wc_get_products( array( 'pa_ingredients' => $term->slug ) );
foreach ( $products as $product ) {
$product_id = wc_get_product_id_by_sku( $product->sku );
$link = get_permalink( $product_id );
echo '<a href="' . $link . '">' . $product->name . '</a>';
}
}
Thanks!