K
K
karl12342022-02-13 03:06:27
WordPress
karl1234, 2022-02-13 03:06:27

For what reason it is not possible to display the attributes in the product card?

Hello everyone, please tell me for what reason it is not possible to correctly display the attributes in the
product card : on it in the attributes there is either 1 floor or a garage, etc. but in archival cards it constantly shows that there is nothing!

But if you click on the filter, then everything will be displayed correctly, if you reset the filter, then the attributes will be empty again, please help, what's wrong ??

Here is the output code for this page:

<?php

if ( ! defined( 'ABSPATH' ) ) {

 exit; // Exit if accessed directly

}

get_header('inner'); ?>



<section class="project_description">

 <div class="container">

  <div class="row">

     <div class="col-md-9 col-sm-8 property-block-grid">

       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

       <div class="col-md-6 col-lg-4 col-sm-6">

         <div class="inner-box">

           <div class="image-box">

             <figure class="image"><a href="<?php the_permalink(); ?>">

                 <?php the_post_thumbnail('medium'); ?>

               </a></figure>

             <?php if( get_field('значок') == 'Новое' ): ?>

             <div class="ribbon">Новое</div>

             <?php elseif( get_field('значок') == 'Цена снижена' ): ?>

             <div class="ribbon">Цена снижена</div>

             <?php elseif( get_field('значок') == 'Популярный' ): ?>

             <div class="ribbon">Популярный</div>

             <?php elseif( get_field('значок') == 'Хит продаж' ): ?>

             <div class="ribbon">Хит продаж</div>

             <?php else: ?>

             <?php  $label = get_field('значок'); ?>

             <?php if( get_field('значок')): ?>

             <div class="ribbon">

               <?= $label['label']; ?>

             </div>

             <?php endif; ?>

             <?php endif; ?>



             <a href="<?php the_permalink(); ?>" class="read-more-link">Подробнее</a>

           </div>

           <div class="lower-content">

             <h3><a href="<?php the_permalink(); ?>">

                 <?php the_title(); ?>

               </a></h3>

             <div class="desc-text">

               <?php if(get_field('описание_товара_новое') == true): ?>

               <p>

                 <?php echo wp_trim_words( get_field('описание_товара_новое' ), $num_words = 9, $more = '...' ); ?>

               </p>

               <?php else: ?>

               <?php the_excerpt();?>

               <?php endif; ?>

             </div>

             <ul class="specs-list clearfix">



               <?php

//Получаем аттрибуты проекта

$area = get_post_meta( get_the_ID(), '_regular_price', true);

$attrName1 = 'pa_rooms';

$attr1 = wc_get_product_terms( $product->id, $attrName1 ) ;

$attrName2 = 'pa_bathroom';

$attr2 = wc_get_product_terms( $product->id, $attrName2 ) ;

$attrName3 = 'pa_garaz';

$attr3 = wc_get_product_terms( $product->id, $attrName3 ) ;

?>



               <li>

                 <div class="outer">

                   <div class="icon"><span class="fas fa-vector-square"></span></div>

                   <div class="info">

                     <?php if($area){echo $area.' м²'; }else {echo "Не указано";} ?>

                   </div>

                 </div>

               </li>

               <li>

                 <div class="outer">

                   <div class="icon"><span class="fas fa-couch"></span></div>

                   <!-- <div class="info"><?=(int)$attr1[0]?> комнат</div> -->

                   <div class="info">

                     <?php  $room = (int)$attr1[0]; ?>

                     <?php if(!$room): ?>

                     Без комнат

                     <?php elseif($room == '1'): ?>

                     1 комната

                     <?php elseif($room == '2' || $room == '3' || $room == '4' ): ?>

                     <?php echo $room.' комнаты';  ?>

                     <?php elseif($room > '4'): ?>

                     <?php echo $room.' комнат';  ?>

                     <?php endif;  ?>

                   </div>

                 </div>

               </li>

               <li>

                 <div class="outer">

                   <div class="icon"><span class="fas fa-bath"></span></div>

                   <!-- <div class="info"><?=(int)$attr2[0]?> санузлов</div> -->

                   <div class="info">

                     <?php  $bathroom = (int)$attr2[0]; ?>

                     <?php if(!$bathroom): ?>

                     без санузла

                     <?php elseif($bathroom == '1'): ?>

                     1 санузел

                     <?php elseif($bathroom == '2' || $bathroom == '3' || $bathroom == '4' ): ?>

                     <?php echo $bathroom.' санузла';  ?>

                     <?php elseif($bathroom > '4'): ?>

                     <?php echo $bathroom.' санузлов';  ?>

                     <?php endif;  ?>

                   </div>

                 </div>

               </li>

               <li>

                 <div class="outer">

                   <div class="icon"><span class="fas fa-car"></span></div>

                   <!-- <div class="info"><?=(int)$attr2[0]?> машина</div> -->

                   <div class="info">

                     <?php  $car = (int)$attr3[0]; ?>

                     <?php if(!$car): ?>

                     без гаража

                     <?php elseif($car == '1'): ?>

                     1 машина

                     <?php elseif($car == '2' || $car == '3' || $car == '4' ): ?>

                     <?php echo $car.' машины';  ?>

                     <?php elseif($car > '4'): ?>

                     <?php echo $car.' машин';  ?>

                     <?php endif;  ?>

                   </div>



                 </div>

               </li>

             </ul>

           </div>

         </div>

       </div>

       <?php endwhile;



else: ?>



       <p>Проектов, соответствующих задаваемым параметрам, не найдено.</p>



       <?php endif; ?>



     </div>

     <aside class="col-md-3 col-sm-4 col-xs-12">

       <div class="row">

         <div class="tg-theme-heading">

           <h2>Подбор по параметрам</h2>

         </div>

         <div class="filter-product">

           <?php dynamic_sidebar( 'filtr' ); ?>

         </div>

       </div>

     </aside>

   </div>



   <div class="row">

     <div class="text-center">

       <?php // 'next_text'    => __('→'),  'prev_text'    => __('←'),

$args = array( 'prev_next'    => true, 'prev_text'    => __(''),

 'next_text'    => __(''), 'mid_size'     => 3, 'end_size'     => 3, 'screen_reader_text' => false,);

                $thePagination =  get_the_posts_pagination($args);

echo preg_replace('~(<h2\\s(class="screen-reader-text")(.*)[$>])(.*)(</h2>)~ui', '', $thePagination);

?>

     </div>

   </div>



   <div class="row">

     <div class="col-md-12">

       <?php

 // Выводим контент старой страницы проектов

 $id = 1468;

 $post = get_post($id);

 $content = $post->post_content;

 $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

 if( $paged == '1' && is_shop() ):



 if( $_GET["swoof"] == false ):

     echo $content;

 endif;



 endif; ?>

     </div>

   </div>





 </div>

</section>



<?php get_footer(); ?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question