$parent_prod = get_field('product_variaties');
  if($parent_prod):
  $variaties = array();
  foreach ($parent_prod as $parent_single):
    $product = wc_get_product($parent_single);
    $id_hoofd = $product->get_ID();
    echo '<h2>'.$product->get_title().'</h2>';
    $variations = $product->get_available_variations();
    $variations_id = wp_list_pluck( $variations, 'variation_id' );
    $args = array(
      'post_type' => array('product_variation'),
      'post__in' => $variations_id,
      'posts_per_page' => -1,
      'facetwp' => false
      );
    ?>
    <table class="table table-striped">
    <?php
    $loop = new WP_Query($args);
    while ($loop->have_posts()) : $loop->the_post();
        global $product;
        $id = $product->get_id(); ?>
          <tr>
            <td class="col-6" style="vertical-align: middle;">
              <span class="ttl"><?php the_title(); ?></span>
            </td>
            <td class="col-2" style="vertical-align: middle;">
              <span class="price"><?php echo $product->get_price_html(); ?></span>
            </td>
            <td class="col-4" style="vertical-align: middle;">
              <?php

              $variaties_in_cart = wp_list_pluck(WC()->cart->get_cart_contents(), 'variation_id');
               if ( in_array($id, $variaties_in_cart) ): ?>
              <a href="<?php echo strstr($product->add_to_cart_url(), '?');?>" class="btn btn-secondary disabled">Ingeschreven</a>
            <?php else: ?>
              <a href="<?php echo strstr($product->add_to_cart_url(), '?');?>" class="btn btn-primary">Inschrijven</a>
            <?php endif; ?>
            </td>
          </tr>
    <?php endwhile; wp_reset_query(); ?>
  </table><?php
  endforeach;
endif; ?>
Geef een reactie 0