Advertisement
nshelper

Untitled

Aug 8th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. foreach ( $results as $key => $post ) {
  2.  
  3. do_action( 'woocommerce/cart_loop/start', $post );
  4.  
  5. if ( in_array( $post->post_type, array( 'product', 'product_variation' ) ) ) {
  6. if ( isset( $this->request['full_screen'] ) || $custom_post_types_limits ) {
  7. if ( $post_types_limits['products'] < 1 ) {
  8. continue;
  9. }
  10. $post_types_limits['products'] --;
  11. }
  12. $product = wc_get_product( $post );
  13. $product_image = wp_get_attachment_image_src( $product->get_image_id(), 'woocommerce_thumbnail' );
  14.  
  15. // if ($product->get_type() == 'variation'){
  16. // $product_image = wp_get_attachment_image_src($product->get_image_id(), 'woocommerce_thumbnail');
  17. // }
  18.  
  19. add_filter( 'woocommerce_get_availability_class', 'etheme_wc_get_availability_class', 20, 2 );
  20.  
  21.  
  22. $all_count = '';
  23.  
  24. if ( isset( $post_types_counts['product'] ) ) {
  25. $all_count = $post_types_counts['product'];
  26. }
  27.  
  28. if ( isset( $post_types_counts['products'] ) ) {
  29. $all_count = $post_types_counts['products'];
  30. }
  31.  
  32.  
  33. $product_args = array(
  34. 'type' => 'Product',
  35. 'id' => $product->get_id(),
  36. 'value' => $product->get_title(),
  37. 'url' => $product->get_permalink(),
  38. 'img' => ( $product_image[0] ) ? $product_image[0] : wc_placeholder_img_src( 'woocommerce_thumbnail' ),
  39. 'arrow' => $arrow,
  40. 'price' => $product->get_price_html(),
  41. 'stock' => wc_get_stock_html( $product ),
  42. 'in_stock' => $product->is_in_stock(),
  43. 'all_count' => $all_count,
  44. 's' => $query
  45. // 'date' => '',
  46. );
  47.  
  48. if ( $just_catalog && get_theme_mod( 'just_catalog_price', 0 ) ) {
  49. $login_text = get_theme_mod( 'ltv_price', esc_html__( 'Login to view price', 'xstore-core' ) );
  50. if ( $login_text == '' ) {
  51. unset( $product_args['price'] );
  52. } else {
  53. $product_args['price'] = $login_text;
  54. }
  55. }
  56.  
  57. // @deprecated 'etheme_ajax_search_products_sku' since v4.3.4 and used in_array('ajax-search-results', (array)get_theme_mod('product_sku_locations', array('cart', 'popup_added_to_cart', 'mini-cart')))
  58. // @todo remove 'etheme_ajax_search_products_sku' in v4.6
  59. if ( ( in_array( 'ajax-search-results', (array) get_theme_mod( 'product_sku_locations', array(
  60. 'cart',
  61. 'popup_added_to_cart',
  62. 'mini-cart'
  63. ) ) ) || apply_filters( 'etheme_ajax_search_products_sku', false ) || $is_shortcode ) && wc_product_sku_enabled() && ( $product->get_sku() || $product->get_type() == 'variable' ) ) {
  64.  
  65. $product_args = array_merge( $product_args,
  66. array(
  67. 'sku' => esc_html__( 'SKU:', 'xstore-core' ) . '<span class="sku">' . ( ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'xstore-core' ) ) . '</span>'
  68. )
  69. );
  70.  
  71. }
  72.  
  73. remove_filter( 'woocommerce_get_availability_class', 'etheme_wc_get_availability_class', 20, 2 );
  74.  
  75. if ( isset( $this->request['full_screen'] ) ) {
  76.  
  77. $product_args['arrow'] = false;
  78. // unset($product_args['arrow']);
  79.  
  80. $product_attr = array(
  81. 'href = "' . $product->add_to_cart_url() . '"',
  82. 'quantity="1"',
  83. 'class = "' . implode(
  84. ' ',
  85. array_filter(
  86. array(
  87. 'button',
  88. 'product_type_' . $product->get_type(),
  89. $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
  90. $product->supports( 'ajax_add_to_cart' ) && $product->is_purchasable() && $product->is_in_stock() ? 'ajax_add_to_cart' : '',
  91. )
  92. )
  93. ) . '"',
  94. 'data-product_id = "' . $product->get_id() . '"',
  95. 'data-product_sku = "' . $product->get_sku() . '"',
  96. 'aria-label = "' . $product->add_to_cart_description() . '"',
  97. 'rel="nofollow"',
  98. );
  99.  
  100. $product_args = array_merge( $product_args,
  101. array(
  102. 'add_to_cart_text' => $product->add_to_cart_text(),
  103. 'add_to_cart_args' => implode( ' ', $product_attr )
  104. ) );
  105. }
  106.  
  107. $suggestions[] = $product_args;
  108.  
  109. } // elseif( in_array( $post->post_type, array( 'page', 'post', 'etheme_portfolio' ) ) ) {
  110. else {
  111. if ( isset( $this->request['full_screen'] ) || $custom_post_types_limits ) {
  112. if ( $post_types_limits[ $post->post_type ] < 1 ) {
  113. continue;
  114. }
  115. $post_types_limits[ $post->post_type ] --;
  116. }
  117. $args = array(
  118. 'type' => ucfirst( str_replace( array( 'page', 'post', 'etheme_portfolio' ), array(
  119. 'Pages',
  120. 'Post',
  121. 'Portfolio'
  122. ), $post->post_type ) ),
  123. 'id' => $post->ID,
  124. 'value' => get_the_title( $post->ID ),
  125. 'url' => get_the_permalink( $post->ID ),
  126. 'img' => ( isset( $this->request['full_screen'] ) && $post->post_type == 'page' ) ? false : get_the_post_thumbnail_url( $post->ID, 'medium' ),
  127. 'arrow' => $arrow,
  128. 'date' => get_the_date( '', $post->ID ),
  129. 'all_count' => isset($post_types_counts[ $post->post_type ]) ? $post_types_counts[ $post->post_type ] : 0,
  130. 's' => $query
  131. );
  132.  
  133. if ( isset( $this->request['full_screen'] ) ) {
  134. if ( $post->post_type == 'post' ) {
  135. ob_start();
  136. etheme_byline(
  137. array(
  138. 'author' => 0,
  139. 'time' => 0,
  140. 'ID' => $post->ID,
  141. 'views_counter' => true
  142. )
  143. );
  144. $args['meta'] = ob_get_clean();
  145. // $excerpt_length = etheme_get_option('excerpt_length', 25);
  146. // ob_start();
  147. // if ( $excerpt_length > 0 ) {
  148. // if ( strlen($post->post_excerpt) > 0 ) {
  149. // $excerpt_length = apply_filters( 'excerpt_length', $excerpt_length );
  150. // $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
  151. // $excerpt = wp_trim_words( $post->post_excerpt, $excerpt_length, $excerpt_more );
  152. // echo do_shortcode(apply_filters( 'wp_trim_excerpt', $excerpt, $excerpt ));
  153. // }
  154. // else
  155. // echo do_shortcode($post->post_excerpt);
  156. // }
  157. // $args['excerpt'] = ob_get_clean();
  158. $args['post_class'] = implode( ' ', get_post_class( 'blog-post post-grid byline-on content-grid', $post->ID ) );
  159.  
  160. } elseif ( $post->post_type == 'etheme_portfolio' && function_exists('etheme_project_categories') ) {
  161. $args['post_class'] = implode( ' ', get_post_class( 'portfolio-item port-style-default', $post->ID ) );
  162. ob_start();
  163. etheme_project_categories( $post->ID );
  164. $args['categories'] = ob_get_clean();
  165. }
  166. }
  167.  
  168. $suggestions[] = $args;
  169. }
  170.  
  171. do_action( 'woocommerce/cart_loop/end', $post );
  172. }
  173.  
  174. $suggestions = $this->parse_suggestions( $products, $suggestions );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement