Вариативные товары

Код для functions.php

//удаляем всё о продукте
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_rating', '10');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', '10');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', '20');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', '30');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta', '40');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_sharing', '50');

//удаляем галерею
remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', '10');
remove_action('woocommerce_before_single_product_summary', 'woocommerce_show_product_images', '20');
//переносим галерею
//add_action('woocommerce_single_product_summary', 'woocommerce_show_product_sale_flash', '10');
//add_action('woocommerce_single_product_summary', 'woocommerce_show_product_images', '20');

/*
 * Вывод вариативных товаров
 */
function ip_varible_products() {
  global $product;
  echo '<div class="var__wrap">';
  $variations = $product->get_available_variations();
  foreach($variations as $variation) {
    $variation_id = $variation['variation_id'];
    //https://woocommerce.github.io/code-reference/classes/WC-Product-Variation.html
    $WC_Product_Variation = new WC_Product_Variation($variation_id);
    /* $attributes = $WC_Product_Variation; */
    /* echo '<pre>'; print_r( $attributes ); echo '</pre>'; */
    ?>
        <div class="var__item">
          <div class="var__img"><?php echo $WC_Product_Variation->get_image('woocommerce_thumbnail'); ?></div>
          <div class="var__name"><?php echo $WC_Product_Variation->get_name(); ?></div>
          <div class="var__price"><?php echo $WC_Product_Variation->get_price_html(); ?></div>
          <div class="var__desc"><?php echo $WC_Product_Variation->get_description(); ?></div>
          <div class="var__btn">
            <a href="<?php echo $WC_Product_Variation->add_to_cart_url(); ?>" class="button add_to_cart_button"><?php echo $WC_Product_Variation->add_to_cart_text(); ?></a>
          </div>
        </div>
  <?php }
  echo '</div>';
}

add_action('woocommerce_single_product_summary', 'ip_varible_products', '60');

css

/* IP Variations */
.var__wrap {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}
.var__item {
  width: 30%;
  margin-bottom: 2em;
  display: flex;
  flex-direction: column;
  text-align: center;
}
.var__name {
  font-size: 1.2em;
  font-weight: bold;
}
.var__img {
  height: 300px;
}
.var__img img {
  max-height: 300px;
}
.var__price {
  margin-top: 1em;
  font-size: 1.2em;
  color: #FC5C00;
  font-weight: bold;
}
.var__desc {
  margin-top: 1em;
}
.var__btn {
  margin-top: 1em;
}
Обратный звонок

Задать вопрос

Заполните форму обратной связи и я свяжусь с вами в ближайшее время