PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/Ultimate_VC_Addons/woocomposer/modules/design-loop-style01.php

https://gitlab.com/ezgonzalez/integral
PHP | 384 lines | 382 code | 1 blank | 1 comment | 106 complexity | ecbcdff0097a8922b4dbbd375da4589d MD5 | raw file
  1. <?php
  2. function WooComposer_Loop_style01($atts,$element){
  3. global $woocommerce;
  4. $product_style = $display_elements = $quick_view_style = $img_animate = $text_align = $color_heading = $color_categories = $color_price = '';
  5. $color_rating = $color_rating_bg = $color_quick_bg = $color_quick = $color_cart_bg = $color_cart = $color_product_desc = $advanced_opts = '';
  6. $color_product_desc_bg = $size_title = $size_cat = $size_price = $color_on_sale = $color_on_sale_bg = $label_on_sale = $product_animation = '';
  7. $disp_type = $category = $output = $product_style = $border_style = $border_color = $border_size = $border_radius = $lazy_images = $pagination = '';
  8. $sale_price = $shortcode = $on_sale_alignment = $on_sale_style = $product_img_disp = '';
  9. extract(shortcode_atts(array(
  10. "disp_type" => "",
  11. "category" => "",
  12. "shortcode" => "",
  13. "product_style" => "style01",
  14. "display_elements" => "",
  15. "quick_view_style" => "expandable",
  16. "label_on_sale" => "Sale!",
  17. "text_align" => "left",
  18. "img_animate" => "rotate-clock",
  19. "pagination" => "",
  20. "color_heading" => "",
  21. "color_categories" => "",
  22. "color_price" => "",
  23. "color_rating" => "",
  24. "color_rating_bg" => "",
  25. "color_quick_bg" => "",
  26. "color_quick" => "",
  27. "color_cart_bg" => "",
  28. "color_on_sale_bg" => "",
  29. "color_on_sale" => "",
  30. "color_cart" => "",
  31. "color_product_desc" => "",
  32. "color_product_desc_bg" => "",
  33. "size_title" => "",
  34. "size_cat" => "",
  35. "size_price" => "",
  36. "border_style" => "",
  37. "border_color" => "",
  38. "border_size" => "",
  39. "border_radius" => "",
  40. "product_animation" => "",
  41. "lazy_images" => "",
  42. "advanced_opts" => "",
  43. "sale_price" => "",
  44. "on_sale_style" => "wcmp-sale-circle",
  45. "on_sale_alignment" => "wcmp-sale-right",
  46. "product_img_disp" => "single",
  47. ),$atts));
  48. $output = $heading_style = $cat_style = $price_style = $cart_style = $cart_bg_style = $view_style = $view_bg_style = $rating_style = '';
  49. $desc_style = $label_style = $on_sale = $class = $style = $border = $desc_style = $sale_price_size = $text_align_style = '';
  50. $image_size = apply_filters( 'single_product_large_thumbnail_size', 'shop_single' );
  51. $img_animate = 'wcmp-img-'.$img_animate;
  52. if($sale_price !== ''){
  53. $sale_price_size = 'font-size:'.$sale_price.'px;';
  54. }
  55. if($border_style !== ''){
  56. $border .= 'border:'.$border_size.'px '.$border_style.' '.$border_color.';';
  57. $border .= 'border-radius:'.$border_radius.'px;';
  58. }
  59. if($color_product_desc_bg !== ''){
  60. $desc_style .= 'background:'.$color_product_desc_bg.';';
  61. }
  62. if($color_product_desc !== ''){
  63. $desc_style .= 'color:'.$color_product_desc.';';
  64. }
  65. $columns = 3;
  66. $display_type = $disp_type;
  67. if($color_heading !== ""){
  68. $heading_style = 'color:'.$color_heading.';';
  69. }
  70. if($size_title !== ""){
  71. $heading_style .= 'font-size:'.$size_title.'px;';
  72. }
  73. if($color_categories !== ""){
  74. $cat_style = 'color:'.$color_categories.';';
  75. }
  76. if($size_cat !== ""){
  77. $cat_style .= 'font-size:'.$size_cat.'px;';
  78. }
  79. if($color_price !== ""){
  80. $price_style = 'color:'.$color_price.';';
  81. }
  82. if($size_price !== ""){
  83. $price_style .= 'font-size:'.$size_price.'px;';
  84. }
  85. if($color_rating !== ""){
  86. $rating_style .= 'color:'.$color_rating.';';
  87. }
  88. if($color_rating_bg !== ""){
  89. $rating_style .= 'background:'.$color_rating_bg.';';
  90. }
  91. if($color_quick_bg !== ""){
  92. $view_bg_style = 'background:'.$color_quick_bg.';';
  93. }
  94. if($color_quick !== ""){
  95. $view_style = 'color:'.$color_quick.';';
  96. }
  97. if($color_cart_bg !== ""){
  98. $cart_bg_style = 'background:'.$color_cart_bg.';';
  99. }
  100. if($color_cart !== ""){
  101. $cart_style = 'color:'.$color_cart.';';
  102. }
  103. if($color_on_sale_bg !== ""){
  104. $label_style = 'background:'.$color_on_sale_bg.';';
  105. }
  106. if($color_on_sale !== ""){
  107. $label_style .= 'color:'.$color_on_sale.';';
  108. }
  109. $elemets = explode(",",$display_elements);
  110. if($element == "grid"){
  111. $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  112. } else {
  113. $paged = 1;
  114. }
  115. $post_count = '12';
  116. /* $output .= do_shortcode($content); */
  117. if($shortcode !== ''){
  118. $new_shortcode = rawurldecode( base64_decode( strip_tags( $shortcode ) ) );
  119. }
  120. $pattern = get_shortcode_regex();
  121. $shortcode_str = $short_atts = '';
  122. preg_match_all("/".$pattern."/",$new_shortcode,$matches);
  123. $shortcode_str = str_replace('"','',str_replace(" ","&",trim($matches[3][0])));
  124. $short_atts = parse_str($shortcode_str);//explode("&",$shortcode_str);
  125. if(isset($matches[2][0])): $display_type = $matches[2][0]; else: $display_type = ''; endif;
  126. if(!isset($columns)): $columns = '4'; endif;
  127. if(isset($per_page)): $post_count = $per_page; endif;
  128. if(isset($number)): $post_count = $number; endif;
  129. if(!isset($order)): $order = 'asc'; endif;
  130. if(!isset($orderby)): $orderby = 'date'; endif;
  131. if(!isset($category)): $category = ''; endif;
  132. if(!isset($ids)): $ids = ''; endif;
  133. if($ids){
  134. $ids = explode( ',', $ids );
  135. $ids = array_map( 'trim', $ids );
  136. }
  137. $col = $columns;
  138. if($columns == "2") $columns = 6;
  139. elseif($columns == "3") $columns = 4;
  140. elseif($columns == "4") $columns = 3;
  141. $meta_query = '';
  142. if($display_type == "recent_products"){
  143. $meta_query = WC()->query->get_meta_query();
  144. }
  145. if($display_type == "featured_products"){
  146. $meta_query = array(
  147. array(
  148. 'key' => '_visibility',
  149. 'value' => array('catalog', 'visible'),
  150. 'compare' => 'IN'
  151. ),
  152. array(
  153. 'key' => '_featured',
  154. 'value' => 'yes'
  155. )
  156. );
  157. }
  158. if($display_type == "top_rated_products"){
  159. add_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
  160. $meta_query = WC()->query->get_meta_query();
  161. }
  162. $args = array(
  163. 'post_type' => 'product',
  164. 'post_status' => 'publish',
  165. 'ignore_sticky_posts' => 1,
  166. 'posts_per_page' => $post_count,
  167. 'orderby' => $orderby,
  168. 'order' => $order,
  169. 'paged' => $paged,
  170. 'meta_query' => $meta_query
  171. );
  172. if($display_type == "sale_products"){
  173. $product_ids_on_sale = woocommerce_get_product_ids_on_sale();
  174. $meta_query = array();
  175. $meta_query[] = $woocommerce->query->visibility_meta_query();
  176. $meta_query[] = $woocommerce->query->stock_status_meta_query();
  177. $args['meta_query'] = $meta_query;
  178. $args['post__in'] = $product_ids_on_sale;
  179. }
  180. if($display_type == "best_selling_products"){
  181. $args['meta_key'] = 'total_sales';
  182. $args['orderby'] = 'meta_value_num';
  183. $args['meta_query'] = array(
  184. array(
  185. 'key' => '_visibility',
  186. 'value' => array( 'catalog', 'visible' ),
  187. 'compare' => 'IN'
  188. )
  189. );
  190. }
  191. if($display_type == "product_category"){
  192. $args['tax_query'] = array(
  193. array(
  194. 'taxonomy' => 'product_cat',
  195. 'terms' => array( esc_attr( $category ) ),
  196. 'field' => 'slug',
  197. 'operator' => 'IN'
  198. )
  199. );
  200. }
  201. if($display_type == "product_categories"){
  202. $args['tax_query'] = array(
  203. array(
  204. 'taxonomy' => 'product_cat',
  205. 'terms' => $ids,
  206. 'field' => 'term_id',
  207. 'operator' => 'IN'
  208. )
  209. );
  210. }
  211. $test = '';
  212. if(vc_is_inline()){
  213. $test = "wcmp_vc_inline";
  214. }
  215. if($product_animation == ''){
  216. $product_animation = 'no-animation';
  217. } else {
  218. $style .= 'opacity:1;';
  219. }
  220. if($element == "grid"){
  221. $class = 'vc_span'.$columns.' ';
  222. }
  223. $output .= '<div class="woocomposer '.$test.'" data-columns="'.$col.'">';
  224. $query = new WP_Query( $args );
  225. if($query->have_posts()):
  226. while ( $query->have_posts() ) : $query->the_post();
  227. $product_id = get_the_ID();
  228. $uid = uniqid();
  229. $output .= '<div id="product-'.$uid.'" style="'.$style.'" class="'.$class.' wpb_column column_container wooproduct" data-animation="animated '.$product_animation.'">';
  230. if($element == 'carousel'){
  231. $output .= '<div class="wcmp-carousel-item">';
  232. }
  233. $product_title = get_the_title($product_id);
  234. $post = get_post($product_id);
  235. $product_desc = get_post($product_id)->post_excerpt;
  236. $product_img = wp_get_attachment_image_src( get_post_thumbnail_id($product_id),$image_size);
  237. $product = new WC_Product( $product_id );
  238. $attachment_ids = $product->get_gallery_attachment_ids();
  239. $price = $product->get_price_html();
  240. $rating = $product->get_rating_html();
  241. $attributes = $product->get_attributes();
  242. $stock = $product->is_in_stock() ? 'InStock' : 'OutOfStock';
  243. if ( $product->is_on_sale() ) :
  244. $on_sale = apply_filters( 'woocommerce_sale_flash', $label_on_sale , $post, $product );
  245. else:
  246. $on_sale = '';
  247. endif;
  248. if($quick_view_style == "expandable"){
  249. $quick_view_class = 'quick-view-loop';
  250. } else {
  251. $quick_view_class = 'quick-view-loop-popup';
  252. }
  253. $cat_count = sizeof( get_the_terms( $product_id, 'product_cat' ) );
  254. $tag_count = sizeof( get_the_terms( $product_id, 'product_tag' ) );
  255. $categories = $product->get_categories(', ','<span class="posted_in">'._n('','',$cat_count,'woocommerce').' ','.</span>');
  256. $tags = $product->get_tags( ', ','<span class="tagged_as">'._n('', '',$tag_count, 'woocommerce').' ', '.</span>' );
  257. $output .= "\n".'<div class="wcmp-product woocommerce wcmp-'.$product_style.' '.$img_animate.'" style="'.$border.' '.$desc_style.'">';
  258. $output .= "\n\t".'<div class="wcmp-product-image">';
  259. if(empty($attachment_ids) && count($attachment_ids) > 1 && $product_img_disp == "carousel"){
  260. $uniqid = uniqid();
  261. $output .= '<div class="wcmp-single-image-carousel carousel-in-loop">';
  262. $product_img = wp_get_attachment_image_src( get_post_thumbnail_id($product_id),$image_size);
  263. if($lazy_images == "enable"){
  264. $src = plugins_url('../assets/img/loader.gif',__FILE__);
  265. } else {
  266. $src = $product_img[0];
  267. }
  268. $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></div></div>';
  269. foreach($attachment_ids as $attachment_id){
  270. $product_img = wp_get_attachment_image_src( $attachment_id,$image_size);
  271. if($lazy_images == "enable"){
  272. $src = plugins_url('../assets/img/loader.gif',__FILE__);
  273. } else {
  274. $src = $product_img[0];
  275. }
  276. $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></div></div>';
  277. }
  278. $output .= '</div>';
  279. } else {
  280. $product_img = wp_get_attachment_image_src( get_post_thumbnail_id($product_id),$image_size);
  281. if($lazy_images == "enable"){
  282. $src = plugins_url('../assets/img/loader.gif',__FILE__);
  283. } else {
  284. $src = $product_img[0];
  285. }
  286. $output .= '<a href="'.get_permalink($product_id).'"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></a>';
  287. }
  288. if($stock == 'OutOfStock'){
  289. $output .= "\n".'<span class="wcmp-out-stock">'.__('Out Of Stock!','woocomposer').'</span>';
  290. }
  291. if($on_sale !== ''){
  292. $output .= "\n".'<div class="wcmp-onsale '.$on_sale_alignment.' '.$on_sale_style.'"><span class="onsale" style="'.$label_style.' '.$sale_price_size.'">'.$on_sale.'</span></div>';
  293. }
  294. $output .= '<div class="wcmp-add-to-cart" style="'.$cart_bg_style.'"><a style="'.$cart_style.'" title="Add to Cart" href="?add-to-cart='.$product_id.'" rel="nofollow" data-product_id="'.$product_id.'" data-product_sku="" class="add_to_cart_button product_type_simple"><i class="wooicon-cart4"></i></a></div>';
  295. if(in_array("quick",$elemets)){
  296. $output .= '<div class="wcmp-quick-view '.$quick_view_class.'" style="'.$view_bg_style.'"><a style="'.$view_style.'" title="Quick View" href="'.get_permalink($product_id).'"><i class="wooicon-plus32"></i></a></div>';
  297. }
  298. if(in_array("reviews",$elemets)){
  299. $output .= "\n".'<div class="wcmp-star-ratings" style="'.$rating_style.'">'.$rating.'</div>';
  300. }
  301. $output .= '</div>';
  302. if($text_align !== ''){
  303. $text_align_style = 'text-align:'.$text_align.';';
  304. }
  305. $output .= "\n\t".'<div class="wcmp-product-desc" style="'.$text_align_style.'">';
  306. $output .= '<a href="'.get_permalink($product_id).'">';
  307. $output .= "\n\t\t".'<h2 style="'.$heading_style.'">'.$product_title.'</h2>';
  308. $output .= '</a>';
  309. if(in_array("category",$elemets)){
  310. $output .= '<h5 style="'.$cat_style.'">';
  311. if($categories !== ''){
  312. $output .= $categories;
  313. $output .= $tags;
  314. }
  315. $output .= '</h5>';
  316. }
  317. $output .= "\n\t\t".'<div class="wcmp-price"><span class="price" style="'.$price_style.'">'.$price.'</span></div>';
  318. if(in_array("description",$elemets)){
  319. $output .= "\n\t\t".'<div class="wcmp-product-content" style="'.$desc_style.'">'.$product_desc.'</div>';
  320. }
  321. $output .= "\n\t".'</div>';
  322. $output .= "\n\t".'</div>';
  323. if(in_array("quick",$elemets)){
  324. $output .= '<div class="wcmp-quick-view-wrapper" data-columns="'.$col.'">';
  325. if($quick_view_style !== "expandable"){
  326. $output .= '<div class="wcmp-quick-view-wrapper woocommerce product">';
  327. $output .= '<div class="wcmp-close-single"><i class="wooicon-cross2"></i></div>';
  328. }
  329. if(!empty($attachment_ids) && count($attachment_ids) > 1){
  330. $uniqid = uniqid();
  331. $output .= '<div class="slider wcmp-image-carousel wcmp-carousel-'.$uniqid.'" data-class="wcmp-carousel-'.$uniqid.'">';
  332. foreach($attachment_ids as $attachment_id){
  333. $product_img = wp_get_attachment_image_src( $attachment_id,$image_size);
  334. if($lazy_images == "enable"){
  335. $src = plugins_url('../assets/img/loader.gif',__FILE__);
  336. } else {
  337. $src = $product_img[0];
  338. }
  339. $output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></div></div>';
  340. }
  341. $output .= '</div>';
  342. } else {
  343. $product_img = wp_get_attachment_image_src( get_post_thumbnail_id($product_id),$image_size);
  344. if($lazy_images == "enable"){
  345. $src = plugins_url('../assets/img/loader.gif',__FILE__);
  346. } else {
  347. $src = $product_img[0];
  348. }
  349. $output .= '<div class="wcmp-single-image wcmp-quickview-img images"><img class="wcmp-img" src="'.$src.'" data-src="'.$product_img[0].'"/></div>';
  350. }
  351. if($quick_view_style !== "expandable"){
  352. $output .= '<div class="wcmp-product-content-single">';
  353. } else {
  354. $output .= '<div class="wcmp-product-content">';
  355. }
  356. ob_start();
  357. do_action( 'woocommerce_single_product_summary' );
  358. $output .= ob_get_clean();
  359. $output .= '</div>';
  360. $output .= '<div class="clear"></div>';
  361. if($quick_view_style !== "expandable"){
  362. $output .= '</div>';
  363. }
  364. $output .= '</div>';
  365. }
  366. $output .= "\n".'</div>';
  367. if($element == 'carousel'){
  368. $output .= "\n\t".'</div>';
  369. }
  370. endwhile;
  371. endif;
  372. if($pagination == "enable"){
  373. $output .= '<div class="wcmp-paginate">';
  374. $output .= woocomposer_pagination($query->max_num_pages);
  375. $output .= '</div>';
  376. }
  377. $output .= '</div>';
  378. if($display_type == "top_rated_products"){
  379. remove_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
  380. }
  381. wp_reset_postdata();
  382. return $output;
  383. }