PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/fusion-core/shortcodes/class-woo-featured-products-slider.php

https://gitlab.com/webkod3r/tripolis
PHP | 193 lines | 131 code | 46 blank | 16 comment | 29 complexity | 73c9757e22e8dc58158db85ae312e7c1 MD5 | raw file
  1. <?php
  2. class FusionSC_WooFeaturedProductsSlider {
  3. public static $args;
  4. /**
  5. * Initiate the shortcode
  6. */
  7. public function __construct() {
  8. add_filter( 'fusion_attr_woo-featured-products-slider-shortcode', array( $this, 'attr' ) );
  9. add_filter( 'fusion_attr_woo-featured-products-slider-shortcode-carousel', array( $this, 'carousel_attr' ) );
  10. add_shortcode('featured_products_slider', array( $this, 'render' ) );
  11. }
  12. /**
  13. * Render the shortcode
  14. * @param array $args Shortcode paramters
  15. * @param string $content Content between shortcode
  16. * @return string HTML output
  17. */
  18. function render( $args, $content = '' ) {
  19. global $woocommerce, $smof_data;
  20. $html = '';
  21. if( class_exists( 'Woocommerce' ) ) {
  22. $defaults = FusionCore_Plugin::set_shortcode_defaults(
  23. array(
  24. 'class' => '',
  25. 'id' => '',
  26. 'autoplay' => 'no',
  27. 'carousel_layout' => 'title_on_rollover',
  28. 'columns' => '5',
  29. 'column_spacing' => '10',
  30. 'mouse_scroll' => 'no',
  31. 'picture_size' => 'auto',
  32. 'scroll_items' => '',
  33. 'show_buttons' => 'yes',
  34. 'show_cats' => 'yes',
  35. 'show_nav' => 'yes',
  36. 'show_price' => 'yes',
  37. // Internal params
  38. 'post_type' => 'product',
  39. 'posts_per_page' => -1,
  40. 'meta_key' => '_featured',
  41. 'meta_value' => 'yes',
  42. ), $args
  43. );
  44. ( $defaults['show_cats'] == "yes" ) ? ( $defaults['show_cats'] = 'enable' ) : ( $defaults['show_cats'] = 'disable' );
  45. ( $defaults['show_price'] == "yes" ) ? ( $defaults['show_price'] = true ) : ( $defaults['show_price'] = false );
  46. ( $defaults['show_buttons'] == "yes" ) ? ( $defaults['show_buttons'] = true ) : ( $defaults['show_buttons'] = false );
  47. extract( $defaults );
  48. self::$args = $defaults;
  49. $items_in_cart = array();
  50. if ( $woocommerce->cart && $woocommerce->cart->get_cart() && is_array( $woocommerce->cart->get_cart() ) ) {
  51. foreach ( $woocommerce->cart->get_cart() as $cart ) {
  52. $items_in_cart[] = $cart['product_id'];
  53. }
  54. }
  55. $design_class = 'fusion-' . Avada()->settings->get( 'woocommerce_product_box_design' ) . '-product-image-wrapper';
  56. if ( $picture_size == 'fixed' ) {
  57. $featured_image_size = 'shop_single';
  58. } else {
  59. $featured_image_size = 'full';
  60. }
  61. $products = new WP_Query( self::$args );
  62. $product_list = '';
  63. if( $products->have_posts() ) {
  64. while( $products->have_posts() ) {
  65. $products->the_post();
  66. $id = get_the_ID();
  67. $in_cart = in_array( $id, $items_in_cart );
  68. $image = $price_tag = $terms = '';
  69. // Title on rollover layout
  70. if ( $carousel_layout == 'title_on_rollover' ) {
  71. $image = avada_render_first_featured_image_markup( get_the_ID(), $featured_image_size, get_permalink( get_the_ID() ), TRUE, $show_price, $show_buttons, $show_cats );
  72. // Title below image layout
  73. } else {
  74. if ( $show_buttons == 'yes' ) {
  75. $image = avada_render_first_featured_image_markup( get_the_ID(), $featured_image_size, get_permalink( get_the_ID() ), TRUE, FALSE, $show_buttons, 'disable', 'disable' );
  76. } else {
  77. $image = avada_render_first_featured_image_markup( get_the_ID(), $featured_image_size, get_permalink( get_the_ID() ), TRUE, FALSE, $show_buttons, 'disable', 'disable', '', '', 'no' );
  78. }
  79. // Get the post title
  80. $image .= sprintf( '<h4 %s><a href="%s" target="%s">%s</a></h4>', FusionCore_Plugin::attributes( 'fusion-carousel-title' ), get_permalink( get_the_ID() ), '_self', get_the_title() );
  81. $image .= '<div class="fusion-carousel-meta">';
  82. // Get the terms
  83. if ( $show_cats == 'enable' ) {
  84. $image .= get_the_term_list( get_the_ID(), 'product_cat', '', ', ', '' );
  85. }
  86. // Check if we should render the woo product price
  87. if ( $show_price ) {
  88. ob_start();
  89. woocommerce_get_template( 'loop/price.php' );
  90. $image .= sprintf( '<div class="fusion-carousel-price">%s</div>', ob_get_clean() );
  91. }
  92. $image .= '</div>';
  93. }
  94. if( $in_cart ) {
  95. $product_list .= sprintf( '<li %s><div class="%s"><div %s>%s</div></div></li>', FusionCore_Plugin::attributes( 'fusion-carousel-item' ), $design_class . ' fusion-item-in-cart', FusionCore_Plugin::attributes( 'fusion-carousel-item-wrapper' ), $image );
  96. } else {
  97. $product_list .= sprintf( '<li %s><div class="%s"><div %s>%s</div></div></li>', FusionCore_Plugin::attributes( 'fusion-carousel-item' ), $design_class, FusionCore_Plugin::attributes( 'fusion-carousel-item-wrapper' ), $image );
  98. }
  99. }
  100. }
  101. wp_reset_query();
  102. $html = sprintf( '<div %s>', FusionCore_Plugin::attributes( 'woo-featured-products-slider-shortcode' ) );
  103. $html .= sprintf( '<div %s>', FusionCore_Plugin::attributes( 'woo-featured-products-slider-shortcode-carousel' ) );
  104. $html .= sprintf( '<div %s>', FusionCore_Plugin::attributes( 'fusion-carousel-positioner' ) );
  105. $html .= sprintf( '<ul %s>', FusionCore_Plugin::attributes( 'fusion-carousel-holder' ) );
  106. $html .= $product_list;
  107. $html .= '</ul>';
  108. // Check if navigation should be shown
  109. if ( $show_nav == 'yes' ) {
  110. $html .= sprintf( '<div %s><span %s></span><span %s></span></div>', FusionCore_Plugin::attributes( 'fusion-carousel-nav' ),
  111. FusionCore_Plugin::attributes( 'fusion-nav-prev' ), FusionCore_Plugin::attributes( 'fusion-nav-next' ) );
  112. }
  113. $html .= '</div>';
  114. $html .= '</div>';
  115. $html .= '</div>';
  116. }
  117. return $html;
  118. }
  119. function attr() {
  120. $attr['class'] = 'fusion-woo-featured-products-slider fusion-woo-slider';
  121. if( self::$args['class'] ) {
  122. $attr['class'] .= ' ' . self::$args['class'];
  123. }
  124. if( self::$args['id'] ) {
  125. $attr['id'] = self::$args['id'];
  126. }
  127. return $attr;
  128. }
  129. function carousel_attr() {
  130. $attr['class'] = 'fusion-carousel';
  131. if ( self::$args['carousel_layout'] == 'title_below_image' ) {
  132. $attr['class'] .= ' fusion-carousel-title-below-image';
  133. $attr['data-metacontent'] = 'yes';
  134. } else {
  135. $attr['class'] .= ' fusion-carousel-title-on-rollover';
  136. }
  137. $attr['data-autoplay'] = self::$args['autoplay'];
  138. $attr['data-columns'] = self::$args['columns'];
  139. $attr['data-itemmargin'] = self::$args['column_spacing'];
  140. $attr['data-itemwidth'] = 180;
  141. $attr['data-touchscroll'] = self::$args['mouse_scroll'];
  142. $attr['data-imagesize'] = self::$args['picture_size'];
  143. $attr['data-scrollitems'] = self::$args['scroll_items'];
  144. return $attr;
  145. }
  146. }
  147. new FusionSC_WooFeaturedProductsSlider();