Удастся ли получить все продукты и их вариацию по значению таксономического слага и категории продукта в WordPress? - PullRequest
0 голосов
/ 26 октября 2019

Я пытаюсь получить товары по категориям и назначенным им атрибутам. Я пытаюсь получить все цены продукта. У некоторых вариантов товара цена пуста, я пытаюсь игнорировать те, у которых есть условие продажной цены варианта. Я получаю результат из приведенного ниже кода, но он неправильный

<div class="main_table_sec">
               <?php
 $hiterms       = get_terms("product_cat", array(
   "orderby" => "slug",
   "hide_empty" => false,
   "parent" => 40
 ));
 $set_sub_child = array(
   '1' => 'implants',
   '2' => 'cover-screws',
   '3' => 'healing-caps',
   '4' => 'impression-posts',
   '5' => 'model-analogues',
   '6' => 'abutments'
 );
 $catterm       = 'implants';
 $varterm       = 'list-product-price-one';
 $setcbt        = 1;
 foreach ($hiterms as $key => $hiterm) {
   if ($setcbt == 1) {
     $varterm = 'list-product-price-one';
   } elseif ($setcbt == 2) {
     $varterm = 'list-product-price-two';
   } elseif ($setcbt == 3) {
     $varterm = 'list-product-price-three';
   } elseif ($setcbt == 4) {
     $varterm = 'list-product-price-four';
   } elseif ($setcbt == 5) {
     $varterm = 'list-product-price-five';
   } elseif ($setcbt == 6) {
     $varterm = 'list-product-price-six';
   } elseif ($setcbt == 7) {
     $varterm = 'list-product-price-seven';
   } elseif ($setcbt == 8) {
     $varterm = 'list-product-price-eight';
   } elseif ($setcbt == 9) {
     $varterm = 'list-product-price-nine';
   } elseif ($setcbt == 10) {
     $varterm = 'list-product-price-ten';
   } elseif ($setcbt == 11) {
     $varterm = 'list-product-price-eleven';
   } elseif ($setcbt == 12) {
     $varterm = 'list-product-twelve';
   }

   $setrgmrkrtprice   = get_field('regular_market_cat', $hiterm->taxonomy . '_' . $hiterm->term_id);
   $setadiscountprice = get_field('discount_price_cat', $hiterm->taxonomy . '_' . $hiterm->term_id);
   $setdiscountrate   = get_field('discount_rate_cate', $hiterm->taxonomy . '_' . $hiterm->term_id);
 ?>
                 <div class="main_table_sec <?php
   echo "mainsubtable" . $setcbt;
 ?>">


                  <?php
   foreach ($set_sub_child as $key => $subsetvl) {
     $catterm = $subsetvl;
 ?>
                 </thead>
                   <tbody>
                   <?php
     $args = array(
       'post_type' => array(
         'product',
         'product_variation'
       ),
       'post_status' => 'publish',
       'posts_per_page' => -1,
       'tax_query' => array(
         'relation' => 'AND',
         array(
           'taxonomy' => 'product_cat',
           'field' => 'slug',
           'terms' => $catterm
         ),
         array(
           'taxonomy' => 'pa_list-product-price',
           'field' => 'slug',
           'terms' => $varterm
         )

       )
     );
     $args = array(
       'category' => array(
         $catterm
       ),
       'tax_query' => array(
         'relation' => 'AND',
         array(
           'taxonomy' => 'product_cat',
           'field' => 'slug',
           'terms' => $catterm
         ),
         array(
           'taxonomy' => 'pa_list-product-price',
           'field' => 'slug',
           'terms' => $varterm
         )

       )
       // or 'term_taxonomy_id' => 4 i.e. category ID
     );
     foreach (wc_get_products($args) as $product) {
       $product_id                  = $product->get_id();
       $checkpackorsingleseventytwo = get_field('pack_of_6', $product_id);
       $variations                  = $product->get_available_variations();
       foreach ($variations as $variation) {
         $variation_id          = $variation['variation_id'];
         $display_regular_price = $variation['display_regular_price'];
         $display_price         = $variation['display_price'];
         if ($checkpackorsingleseventytwo == 'pack of 6') {
 ?>
   <tr class="<?php
           echo "setblock" . $setcbt;
 ?> ">
                     <td><?php
           echo $product->get_sku();
 ?></td>
                       <td><?php
           echo $product->get_name();
 ?></td>
                       <td><?php
           echo sprintf("%.2f", $display_regular_price);
 ?></td>
                       <td><?php
           echo $display_price;
 ?></td>
 <td class="flx quantity"><div class="qntymsg error-msg"></div> <span class="plus plus-seventytwo-inner"><i class="fa fa-plus" aria-hidden="true"></i></span> <span class="input-tag"><input type="text" data-maincat="<?php
           echo str_replace(" ", "-", strtolower($catterm));
 ?>" data-checkpackorsingleseventytwo="<?php
           echo $checkpackorsingleseventytwo;
 ?>" data-productid="<?php
           echo $product_id;
 ?>" data-variaid="<?php
           echo $variation_id;
 ?>" data-perqntyseventytwoprice="<?php
           echo $display_price;
 ?>" data-perseventytwoqnty="0" data-qntyseventytwoprice="0" class="innrevntytwo qty qty-seventytwo" data-prdctmainsubtable="<?php
           echo $setcbt;
 ?>" min="0" value="0"></span> <span class="minus minus-seventytwo-inner minus-btn"><i class="fa fa-minus" aria-hidden="true"></i></span> </td>
                       <td class="catsum"><?php
           echo $product->get_price();
 ?></td>
                       <td><?php
           echo $discountpert . "%";
 ?></td>
                     </tr><?php
         }
       }
     }
   }
 }
 ?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...