search-result.php
116 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | if( !empty($_GET['s'])) { |
| 5 | |
| 6 | $args = array( |
| 7 | 'orderby' => 'date', |
| 8 | 'post_status' => 'publish', |
| 9 | 'post_type' => esc_attr( $_GET['post_type'] ), |
| 10 | 's' => esc_attr( $_GET['s'] ), |
| 11 | 'posts_per_page' => 30, |
| 12 | ); |
| 13 | |
| 14 | if( !empty( $_GET['product_cat']) ) { |
| 15 | |
| 16 | $cats = explode(',', trim($_GET['product_cat'], ',')); |
| 17 | |
| 18 | $sanitized = array_map(function ($val){ |
| 19 | |
| 20 | return intval($val); |
| 21 | |
| 22 | }, $cats); |
| 23 | |
| 24 | $args['tax_query'] = array( |
| 25 | array( |
| 26 | 'taxonomy' => 'product_cat', |
| 27 | 'field' => 'term_id', |
| 28 | 'terms' => $sanitized, |
| 29 | 'operator' => 'IN' |
| 30 | ) |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | $query = new WP_Query($args); |
| 35 | } |
| 36 | |
| 37 | if( $query->have_posts()): |
| 38 | ?> |
| 39 | |
| 40 | <div class="shopengine-search-product"> |
| 41 | |
| 42 | <?php |
| 43 | while ( $query->have_posts() ) : $query->the_post(); |
| 44 | $id = esc_attr( get_the_ID() ); |
| 45 | $image_url = get_the_post_thumbnail_url( $id ); |
| 46 | $product = wc_get_product( $id ); |
| 47 | $price = wc_price($product->get_price()); |
| 48 | $reg_price = wc_price($product->get_regular_price()); |
| 49 | ?> |
| 50 | |
| 51 | <div class="shopengine-search-product__item"> |
| 52 | <div class="shopengine-search-product__item--image"> |
| 53 | <img src="<?php echo esc_url( $image_url ) ?>"> |
| 54 | </div> |
| 55 | <div class="shopengine-search-product__item--content"> |
| 56 | <h4 class="shopengine-search-product__item--title"> |
| 57 | <a href="<?php the_permalink() ?>"> <?php the_title() ?> </a> |
| 58 | </h4> |
| 59 | <div class="shopengine-product-rating"> |
| 60 | <?php |
| 61 | if($product->get_rating_count() > 0){ |
| 62 | woocommerce_template_loop_rating(); |
| 63 | } else { |
| 64 | $rating_html = '<div class="star-rating">'; |
| 65 | $rating_html .= wc_get_star_rating_html( 0, 0 ); |
| 66 | $rating_html .= '</div>'; |
| 67 | |
| 68 | echo wp_kses_post($rating_html); |
| 69 | } |
| 70 | |
| 71 | // review count |
| 72 | $review_count = $product->get_review_count(); |
| 73 | echo "<span class='rating-count'>(". $review_count .")</span>"; |
| 74 | ?> |
| 75 | </div> |
| 76 | <div class="shopengine-search-product__item--price"> |
| 77 | <?php if( !empty( $product->get_sale_price() ) ) : ?> |
| 78 | <del> |
| 79 | <span class="woocommerce-Price-amount amount"> |
| 80 | <?php echo \Shopengine\Utils\Helper::kses( $reg_price ) ?> |
| 81 | </span> |
| 82 | </del> |
| 83 | <?php endif; ?> |
| 84 | <ins><span class="woocommerce-Price-amount amount"><?php echo \Shopengine\Utils\Helper::kses( $price ) ?> </span></ins> |
| 85 | </div> |
| 86 | </div> |
| 87 | |
| 88 | <a class="shopengine-search-more-btn" href="<?php echo get_the_permalink(); ?>"><i class="fas fa-chevron-right"></i></a> |
| 89 | </div> |
| 90 | |
| 91 | <?php |
| 92 | |
| 93 | endwhile; |
| 94 | wp_reset_query(); |
| 95 | wp_reset_postdata(); |
| 96 | |
| 97 | ?> |
| 98 | |
| 99 | <div class="shopengine-search-product__item"> |
| 100 | <a class="shopengine-search-more-products" href="<?php echo get_the_permalink(get_option('woocommerce_shop_page_id')); ?>"><i class="fas fa-retweet"></i><?php echo esc_html__('More Products', 'shopengine'); ?></a> |
| 101 | </div> |
| 102 | |
| 103 | </div> |
| 104 | |
| 105 | <?php |
| 106 | |
| 107 | else: ?> |
| 108 | <div class="shopengine-search-product"> |
| 109 | <div> |
| 110 | <?php echo esc_html__('No result found', 'shopengine'); ?> |
| 111 | </div> |
| 112 | </div> |
| 113 | <?php |
| 114 | |
| 115 | endif; |
| 116 |