| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateStoreKit\Modules\EddClassicCarousel\Widgets; |
| 4 |
|
| 5 |
use UltimateStoreKit\Base\Module_Base; |
| 6 |
use UltimateStoreKit\Traits\Global_Widget_Controls; |
| 7 |
use UltimateStoreKit\Traits\Global_EDD_Widget_Controls; |
| 8 |
use UltimateStoreKit\Traits\Global_Widget_Template; |
| 9 |
use UltimateStoreKit\Includes\Controls\GroupQuery\Group_Control_Query; |
| 10 |
use WP_Query; |
| 11 |
|
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
// Exit if accessed directly |
| 17 |
|
| 18 |
class EDD_Classic_Carousel extends Module_Base { |
| 19 |
use Global_Widget_Controls; |
| 20 |
use Global_EDD_Widget_Controls; |
| 21 |
use Global_Widget_Template; |
| 22 |
use Group_Control_Query; |
| 23 |
/** |
| 24 |
* @var \WP_Query |
| 25 |
*/ |
| 26 |
private $_query = null; |
| 27 |
public function get_name() { |
| 28 |
return 'usk-edd-classic-carousel'; |
| 29 |
} |
| 30 |
|
| 31 |
public function get_title() { |
| 32 |
return esc_html__('EDD Classic Carousel', 'ultimate-store-kit'); |
| 33 |
} |
| 34 |
|
| 35 |
public function get_icon() { |
| 36 |
return 'usk-widget-icon usk-icon-edd-classic-carousel'; |
| 37 |
} |
| 38 |
|
| 39 |
public function get_categories() { |
| 40 |
return ['ultimate-store-kit']; |
| 41 |
} |
| 42 |
|
| 43 |
public function get_keywords() { |
| 44 |
return ['product', 'product carousel', 'table', 'wc', 'carousel', 'list']; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
public function get_style_depends() { |
| 49 |
if ($this->usk_is_edit_mode()) { |
| 50 |
return ['usk-all-styles']; |
| 51 |
} else { |
| 52 |
return ['usk-font', 'usk-edd-classic-carousel']; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
public function get_query() { |
| 58 |
return $this->_query; |
| 59 |
} |
| 60 |
protected function register_controls() { |
| 61 |
/** |
| 62 |
* ! render controls layout |
| 63 |
*/ |
| 64 |
$this->register_global_edd_controls_carousel_layout(); |
| 65 |
$this->register_global_edd_controls_query(); |
| 66 |
$this->register_global_edd_controls_additional(); |
| 67 |
|
| 68 |
//swiper |
| 69 |
$this->register_global_controls_carousel_navigation(); |
| 70 |
$this->register_global_controls_carousel_settings(); |
| 71 |
|
| 72 |
/** |
| 73 |
* ! render style controls |
| 74 |
*/ |
| 75 |
$this->register_global_edd_style_controls_items(); |
| 76 |
$this->register_global_edd_style_controls_title(); |
| 77 |
$this->register_global_edd_style_controls_category(); |
| 78 |
$this->register_global_edd_style_controls_action_button(); |
| 79 |
$this->register_global_edd_style_controls_price(); |
| 80 |
$this->register_global_controls_navigation_style(); |
| 81 |
} |
| 82 |
|
| 83 |
public function render_header() { |
| 84 |
$settings = $this->get_settings_for_display(); |
| 85 |
$this->add_render_attribute('usk-edd-classic-carousel', 'class', ['usk-edd-classic-carousel', 'usk-content-position-' . $settings['alignment'] . ''], true); |
| 86 |
$this->add_render_attribute('usk-edd-classic-carousel', 'data-filter', [$settings['show_tab']]); |
| 87 |
?> |
| 88 |
<div class="ultimate-store-kit"> |
| 89 |
<div <?php $this->print_render_attribute_string('usk-edd-classic-carousel'); ?>> |
| 90 |
<?php |
| 91 |
} |
| 92 |
public function render_footer() { ?> |
| 93 |
</div> |
| 94 |
</div> |
| 95 |
<?php |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
public function render() { |
| 100 |
$this->register_global_template_carousel_header(); |
| 101 |
$this->render_loop_item(); |
| 102 |
$this->usk_register_global_template_carousel_footer(); |
| 103 |
} |
| 104 |
public function render_loop_item() { |
| 105 |
$settings = $this->get_settings_for_display(); |
| 106 |
$id = 'bdt-edd-classic-carousel-' . $this->get_id(); |
| 107 |
$this->query_product(); |
| 108 |
$wp_query = $this->get_query(); |
| 109 |
// print_r($wp_query); |
| 110 |
if ($wp_query->have_posts()) { |
| 111 |
|
| 112 |
?> |
| 113 |
<?php |
| 114 |
while ($wp_query->have_posts()) { |
| 115 |
$wp_query->the_post(); |
| 116 |
|
| 117 |
$this->add_render_attribute('edd-classic-carousel-item', 'class', 'usk-edd-classic-carousel-item swiper-slide', true); |
| 118 |
?> |
| 119 |
<div <?php $this->print_render_attribute_string('edd-classic-carousel-item'); ?>> |
| 120 |
<div class="usk-edd-classic-carousel-image-wrapper"> |
| 121 |
<div class="usk-edd-classic-carousel-image"> |
| 122 |
<a href="<?php the_permalink(); ?>"> |
| 123 |
<img src="<?php echo esc_url(wp_get_attachment_image_url(get_post_thumbnail_id(), $settings['image_size'])); ?>" alt="<?php echo esc_html(get_the_title()); ?>"> |
| 124 |
</a> |
| 125 |
<div class="usk-action-button"> |
| 126 |
<?php if (function_exists('edd_price')) { ?> |
| 127 |
<?php if (!edd_has_variable_prices(get_the_ID())) { ?> |
| 128 |
<?php echo wp_kses_post(edd_get_purchase_link(get_the_ID(), 'Add to Cart', 'button')); ?> |
| 129 |
<?php } ?> |
| 130 |
<?php } ?> |
| 131 |
<div class="usk-details-button"> |
| 132 |
<a href="<?php the_permalink(); ?>"><span><?php esc_html_e('View Details', 'ultimate-store-kit'); ?></span></a> |
| 133 |
</div> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
|
| 137 |
|
| 138 |
</div> |
| 139 |
<div class="usk-edd-content"> |
| 140 |
<?php |
| 141 |
if ($settings['show_category']) : |
| 142 |
$category_list = wp_get_post_terms(get_the_ID(), 'download_category'); |
| 143 |
foreach ($category_list as $term) { |
| 144 |
$term_link = get_term_link($term); |
| 145 |
echo '<span class="usk-edd-category"><a href="' . esc_url($term_link) . '">' . esc_html($term->name) . '</a></span> '; |
| 146 |
} |
| 147 |
endif; |
| 148 |
|
| 149 |
if ($settings['show_title']) : |
| 150 |
printf('<%1$s class="usk-edd-title"><a href="%2$s">%3$s</a></%1$s>', esc_attr($settings['title_tags']), esc_url(get_the_permalink()), esc_html(get_the_title())); |
| 151 |
endif; |
| 152 |
|
| 153 |
if ($settings['show_price']) : ?> |
| 154 |
<div class="usk-edd-price"> |
| 155 |
<?php if (edd_has_variable_prices(get_the_ID())) { |
| 156 |
esc_html_e('Starting at: ', 'ultimate-store-kit'); |
| 157 |
edd_price(get_the_ID()); |
| 158 |
} else { |
| 159 |
edd_price(get_the_ID()); |
| 160 |
} |
| 161 |
?> |
| 162 |
</div> |
| 163 |
<?php |
| 164 |
endif; ?> |
| 165 |
|
| 166 |
</div> |
| 167 |
</div> |
| 168 |
<?php |
| 169 |
} |
| 170 |
?> |
| 171 |
<?php |
| 172 |
wp_reset_postdata(); |
| 173 |
} |
| 174 |
} |
| 175 |
public function query_product() { |
| 176 |
$settings = $this->get_settings_for_display(); |
| 177 |
$args = []; |
| 178 |
$default = $this->getGroupControlQueryArgs(); |
| 179 |
$args['post_type'] = 'download'; |
| 180 |
$args['posts_per_page'] = $settings['product_limit']; |
| 181 |
$default = $this->getGroupControlQueryArgs(); |
| 182 |
$args = array_merge($default, $args); |
| 183 |
$this->_query = new WP_Query($args); |
| 184 |
} |
| 185 |
} |
| 186 |
|