| @@ -1,458 +1,440 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Main ProductDescription class. | |
| 4 | - * | |
| 5 | - * @package RadiusTheme\SB | |
| 6 | - */ | |
| 7 | - | |
| 8 | -namespace RadiusTheme\SB\Abstracts; | |
| 9 | - | |
| 10 | -use RadiusTheme\SB\Helpers\Fns; | |
| 11 | -use RadiusTheme\SB\Traits\ActionBtnTraits; | |
| 12 | -use RadiusTheme\SB\Elementor\Helper\RenderHelpers; | |
| 13 | -use RadiusTheme\SB\Elementor\Widgets\Controls\StyleFields; | |
| 14 | -use RadiusTheme\SB\Elementor\Widgets\Controls\SliderSettings; | |
| 15 | -use RadiusTheme\SB\Elementor\Widgets\Controls\ProductsSettings; | |
| 16 | -use RadiusTheme\SB\Elementor\Widgets\Controls\ReviewsStarSettings; | |
| 17 | - | |
| 18 | -// Do not allow directly accessing this file. | |
| 19 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 20 | - exit( 'This script cannot be accessed directly.' ); | |
| 21 | -} | |
| 22 | - | |
| 23 | -/** | |
| 24 | - * Product Description class | |
| 25 | - */ | |
| 26 | -abstract class LoopWithProductSlider extends ElementorWidgetBase { | |
| 27 | - /** | |
| 28 | - * Action Button Traits. | |
| 29 | - */ | |
| 30 | - use ActionBtnTraits; | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * Product Loop Settings. | |
| 34 | - * | |
| 35 | - * @var object $loop_settings | |
| 36 | - */ | |
| 37 | - public $loop_settings; | |
| 38 | - /** | |
| 39 | - * Product Loop Settings. | |
| 40 | - * | |
| 41 | - * @var object $loop_settings | |
| 42 | - */ | |
| 43 | - public $has_slider = true; | |
| 44 | - /** | |
| 45 | - * Product Loop Settings. | |
| 46 | - * | |
| 47 | - * @var object $loop_settings | |
| 48 | - */ | |
| 49 | - public $has_title = true; | |
| 50 | - /** | |
| 51 | - * Product Loop Settings. | |
| 52 | - * | |
| 53 | - * @var object $loop_settings | |
| 54 | - */ | |
| 55 | - public $has_pagination = false; | |
| 56 | - /** | |
| 57 | - * This function Will overwrite by the main function' | |
| 58 | - * | |
| 59 | - * @return array | |
| 60 | - */ | |
| 61 | - abstract public function template_data_arg(); | |
| 62 | - /** | |
| 63 | - * Widget Field | |
| 64 | - * | |
| 65 | - * @return array | |
| 66 | - */ | |
| 67 | - public function widget_fields() { | |
| 68 | - $this->loop_settings = new ProductsSettings( $this ); | |
| 69 | - $slider_control = $this->has_slider ? SliderSettings::slider_controls() : []; | |
| 70 | - $slider_style = $this->has_slider ? SliderSettings::slider_style( $this ) : []; | |
| 71 | - $heading = $this->has_title ? $this->loop_settings->heading_controls() : []; | |
| 72 | - $pagination = $this->has_pagination ? $this->loop_settings->pagination() : []; | |
| 73 | - | |
| 74 | - return $this->general_section() + | |
| 75 | - $this->loop_settings->widget_icons() + | |
| 76 | - $slider_control + | |
| 77 | - $heading + | |
| 78 | - $this->loop_settings->image_section() + | |
| 79 | - $this->loop_settings->product_title() + | |
| 80 | - $this->loop_settings->product_price() + | |
| 81 | - $this->loop_settings->flash_sale() + | |
| 82 | - ReviewsStarSettings::widget_fields( $this ) + | |
| 83 | - $this->loop_settings->add_to_cart() + | |
| 84 | - $this->loop_settings->module_button_style() + | |
| 85 | - $slider_style + | |
| 86 | - $pagination + | |
| 87 | - StyleFields::not_found_notice( $this ); | |
| 88 | - } | |
| 89 | - | |
| 90 | - /** | |
| 91 | - * Widget Field | |
| 92 | - * | |
| 93 | - * @return array | |
| 94 | - */ | |
| 95 | - public function general_section() { | |
| 96 | - $fields = $this->loop_settings->general_section(); | |
| 97 | - if ( 'rtsb-related-product' === $this->rtsb_base ) { | |
| 98 | - unset( $fields['orderby'] ); | |
| 99 | - unset( $fields['order'] ); | |
| 100 | - } | |
| 101 | - if ( 'rtsb-products-archive' === $this->rtsb_base ) { | |
| 102 | - unset( $fields['posts_per_page'] ); | |
| 103 | - unset( $fields['columns'] ); | |
| 104 | - unset( $fields['orderby'] ); | |
| 105 | - unset( $fields['order'] ); | |
| 106 | - } | |
| 107 | - return $fields; | |
| 108 | - } | |
| 109 | - | |
| 110 | - /** | |
| 111 | - * Widget Field. | |
| 112 | - * | |
| 113 | - * @return void | |
| 114 | - */ | |
| 115 | - public function script_init() { | |
| 116 | - wp_dequeue_script( 'rtsb-public' ); | |
| 117 | - | |
| 118 | - wp_enqueue_style( 'swiper' ); | |
| 119 | - wp_enqueue_script( 'swiper' ); | |
| 120 | - wp_enqueue_script( 'rtsb-public' ); | |
| 121 | - } | |
| 122 | - | |
| 123 | - /** | |
| 124 | - * Product loop start function | |
| 125 | - * | |
| 126 | - * @return string | |
| 127 | - */ | |
| 128 | - public function product_loop_start( $html = '' ) { | |
| 129 | - $str = explode( 'products', $html ); | |
| 130 | - if ( is_array( $str ) && count( $str ) > 1 ) { | |
| 131 | - $html = $str[0] . ' products swiper-wrapper ' . $str[1]; | |
| 132 | - } | |
| 133 | - $controllers = $this->get_settings_for_display(); | |
| 134 | - | |
| 135 | - $swiper_data = [ | |
| 136 | - // Optional parameters. | |
| 137 | - 'wrapperClass' => 'products', | |
| 138 | - 'slideClass' => 'product', | |
| 139 | - 'slidesPerView' => 4, | |
| 140 | - 'slidesPerGroup' => 3, | |
| 141 | - 'spaceBetween' => 15, | |
| 142 | - 'loop' => false, | |
| 143 | - ]; | |
| 144 | - $classes = []; | |
| 145 | - if ( ! empty( $controllers['columns'] ) ) { | |
| 146 | - $swiper_data['slidesPerView'] = absint( $controllers['columns'] ); | |
| 147 | - $swiper_data['slidesPerGroup'] = absint( $controllers['columns'] ); | |
| 148 | - } | |
| 149 | - if ( ! empty( $controllers['space_between'] ) ) { | |
| 150 | - $swiper_data['spaceBetween'] = absint( $controllers['space_between'] ); | |
| 151 | - } | |
| 152 | - if ( ! empty( $controllers['loop'] ) ) { | |
| 153 | - $swiper_data['loop'] = boolval( $controllers['loop'] ); | |
| 154 | - } | |
| 155 | - if ( ! empty( $controllers['autoplay'] ) ) { | |
| 156 | - $swiper_data['autoplay']['delay'] = absint( $controllers['autoplay_delay'] ); | |
| 157 | - $swiper_data['autoplay']['pauseOnMouseEnter'] = boolval( $controllers['pauseon_mouseenter'] ); | |
| 158 | - $swiper_data['autoplay']['disableOnInteraction'] = false; | |
| 159 | - } | |
| 160 | - if ( ! empty( $controllers['speed'] ) ) { | |
| 161 | - $swiper_data['speed'] = absint( $controllers['speed'] ); | |
| 162 | - } | |
| 163 | - if ( ! empty( $controllers['show_arrows'] ) ) { | |
| 164 | - $swiper_data['navigation'] = [ | |
| 165 | - 'nextEl' => '.button-right', | |
| 166 | - 'prevEl' => '.button-left', | |
| 167 | - ]; | |
| 168 | - $classes[] = 'has-navigation'; | |
| 169 | - } | |
| 170 | - if ( ! empty( $controllers['show_dots'] ) ) { | |
| 171 | - $swiper_data['pagination'] = [ | |
| 172 | - 'el' => '.rtsb-slider-pagination', | |
| 173 | - 'type' => 'bullets', | |
| 174 | - 'clickable' => true, | |
| 175 | - ]; | |
| 176 | - $classes[] = 'has-dots'; | |
| 177 | - } | |
| 178 | - | |
| 179 | - $data = [ | |
| 180 | - 'template' => 'global/slider-header', | |
| 181 | - 'controllers' => $controllers, | |
| 182 | - 'swiper_json_data' => wp_json_encode( $swiper_data ), | |
| 183 | - 'classes' => $classes, | |
| 184 | - ]; | |
| 185 | - $new = Fns::load_template( $data['template'], $data, true ); | |
| 186 | - $html = $new . $html; | |
| 187 | - return $html; | |
| 188 | - } | |
| 189 | - /** | |
| 190 | - * Product loop start function | |
| 191 | - * | |
| 192 | - * @return string | |
| 193 | - */ | |
| 194 | - public function product_loop_end( $html ) { | |
| 195 | - $controllers = $this->get_settings_for_display(); | |
| 196 | - $data = [ | |
| 197 | - 'template' => 'global/slider-footer', | |
| 198 | - 'controllers' => $controllers, | |
| 199 | - 'left_arrow' => Fns::icons_manager( $controllers['left_arrow_icon'] ), | |
| 200 | - 'right_arrow' => Fns::icons_manager( $controllers['right_arrow_icon'] ), | |
| 201 | - ]; | |
| 202 | - $new = Fns::load_template( $data['template'], $data, true ); | |
| 203 | - $html = $html . $new; | |
| 204 | - return $html; | |
| 205 | - } | |
| 206 | - /** | |
| 207 | - * Product loop start function | |
| 208 | - * | |
| 209 | - * @return string | |
| 210 | - */ | |
| 211 | - public function post_class( $classes ) { | |
| 212 | - $classes[] = 'swiper-slide'; | |
| 213 | - return $classes; | |
| 214 | - } | |
| 215 | - | |
| 216 | - /** | |
| 217 | - * Image Wrapper. | |
| 218 | - * | |
| 219 | - * @return void | |
| 220 | - */ | |
| 221 | - public function image_wrapper() { | |
| 222 | - if ( ! RenderHelpers::is_wrapper_needed() ) { | |
| 223 | - return; | |
| 224 | - } | |
| 225 | - ?> | |
| 226 | - <div class="rtsb-image-wrapper"> | |
| 227 | - <?php | |
| 228 | - } | |
| 229 | - /** | |
| 230 | - * Image Wrapper. | |
| 231 | - * | |
| 232 | - * @return void | |
| 233 | - */ | |
| 234 | - public function div_close() { | |
| 235 | - if ( ! RenderHelpers::is_wrapper_needed() ) { | |
| 236 | - return; | |
| 237 | - } | |
| 238 | - ?> | |
| 239 | - </div> | |
| 240 | - <?php | |
| 241 | - } | |
| 242 | - /** | |
| 243 | - * Image Wrapper. | |
| 244 | - * | |
| 245 | - * @return void | |
| 246 | - */ | |
| 247 | - public function product_content_wrapper() { | |
| 248 | - if ( ! RenderHelpers::is_wrapper_needed() ) { | |
| 249 | - return; | |
| 250 | - } | |
| 251 | - ?> | |
| 252 | - <div class="rtsb-product-content"> | |
| 253 | - <?php | |
| 254 | - } | |
| 255 | - | |
| 256 | - /** | |
| 257 | - * Apply hooks function. | |
| 258 | - * | |
| 259 | - * @return void | |
| 260 | - */ | |
| 261 | - public function apply_hooks() { | |
| 262 | - $controllers = $this->get_settings_for_display(); | |
| 263 | - | |
| 264 | - if ( empty( $controllers['show_rating'] ) ) { | |
| 265 | - remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); | |
| 266 | - add_filter( 'woocommerce_product_get_rating_html', '__return_false' ); | |
| 267 | - } | |
| 268 | - if ( empty( $controllers['show_flash_sale'] ) ) { | |
| 269 | - add_filter( 'woocommerce_sale_flash', '__return_false' ); | |
| 270 | - } | |
| 271 | - if ( ! empty( $controllers['slider_activate'] ) ) { | |
| 272 | - add_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] ); | |
| 273 | - add_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] ); | |
| 274 | - add_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 ); | |
| 275 | - $this->script_init(); | |
| 276 | - } | |
| 277 | - | |
| 278 | - if ( class_exists( 'WooProductVariationSwatches' ) ) { | |
| 279 | - remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5 ); | |
| 280 | - remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 20 ); | |
| 281 | - remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 8 ); | |
| 282 | - remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 12 ); | |
| 283 | - } | |
| 284 | - | |
| 285 | - // Remove Action Button | |
| 286 | - add_filter( 'rtsb/module/wishlist/show_button', '__return_false' ); | |
| 287 | - add_filter( 'rtsb/module/quick_view/show_button', '__return_false' ); | |
| 288 | - add_filter( 'rtsb/module/compare/show_button', '__return_false' ); | |
| 289 | - | |
| 290 | - //TODO:: Pro Will move if necessary | |
| 291 | - if ( empty( $controllers['show_quick_checkout'] ) ) { | |
| 292 | - add_filter( 'rtsb/module/quick_checkout/show_button', '__return_false' ); | |
| 293 | - } | |
| 294 | - if ( empty( $controllers['show_flash_sale_countdown'] ) ) { | |
| 295 | - add_filter( 'rtsb/module/flash_sale_countdown/show_counter', '__return_false' ); | |
| 296 | - } | |
| 297 | - | |
| 298 | - // Default Link remove. | |
| 299 | - remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); | |
| 300 | - remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 ); | |
| 301 | - | |
| 302 | - // Image Wrapper open. | |
| 303 | - add_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 ); | |
| 304 | - | |
| 305 | - // Image link. | |
| 306 | - add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 ); | |
| 307 | - add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 ); | |
| 308 | - // Image link end. | |
| 309 | - | |
| 310 | - // Title Link. | |
| 311 | - add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 ); | |
| 312 | - add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 ); | |
| 313 | - // Title Link end. | |
| 314 | - | |
| 315 | - // Image Wrapper close. | |
| 316 | - add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 ); | |
| 317 | - // Content Wrapper Open. | |
| 318 | - add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 ); | |
| 319 | - // Content Wrapper Close. | |
| 320 | - add_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 ); | |
| 321 | - | |
| 322 | - | |
| 323 | - if ( $this->is_edit_mode() ){ | |
| 324 | - if( class_exists( Rtwpvs\Controllers\Hooks::class ) ){ | |
| 325 | - remove_filter( 'woocommerce_ajax_variationX_threshold', [ Rtwpvs\Controllers\Hooks::class, 'ajax_variation_threshold' ], 99 ); | |
| 326 | - } | |
| 327 | - add_filter( 'woocommerce_ajax_variation_threshold', function (){ | |
| 328 | - return 1; | |
| 329 | - }, 99 ); | |
| 330 | - | |
| 331 | - } | |
| 332 | - | |
| 333 | - } | |
| 334 | - /** | |
| 335 | - * Apply hooks function. | |
| 336 | - * | |
| 337 | - * @return void | |
| 338 | - */ | |
| 339 | - public function apply_hooks_set_default() { | |
| 340 | - | |
| 341 | - // Default Link re active. | |
| 342 | - add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); | |
| 343 | - add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 ); | |
| 344 | - | |
| 345 | - // Image Wrapper open. | |
| 346 | - remove_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 ); | |
| 347 | - | |
| 348 | - // Image link. | |
| 349 | - remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 ); | |
| 350 | - remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 ); | |
| 351 | - // Image link end. | |
| 352 | - | |
| 353 | - // Title Link. | |
| 354 | - remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 ); | |
| 355 | - remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 ); | |
| 356 | - // Title Link End. | |
| 357 | - | |
| 358 | - // Image Wrapper close. | |
| 359 | - remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 ); | |
| 360 | - | |
| 361 | - // Content Wrapper Open. | |
| 362 | - remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 ); | |
| 363 | - // Content Wrapper Close. | |
| 364 | - remove_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 ); | |
| 365 | - | |
| 366 | - // Remove Action Button. | |
| 367 | - remove_filter( 'rtsb/module/wishlist/show_button', '__return_false' ); | |
| 368 | - remove_filter( 'rtsb/module/quick_view/show_button', '__return_false' ); | |
| 369 | - remove_filter( 'rtsb/module/compare/show_button', '__return_false' ); | |
| 370 | - | |
| 371 | - } | |
| 372 | - /** | |
| 373 | - * Related Product Args function' | |
| 374 | - * | |
| 375 | - * @param [type] $args argument. | |
| 376 | - * @return array | |
| 377 | - */ | |
| 378 | - public function products_args( $args ) { | |
| 379 | - $controllers = $this->get_settings_for_display(); | |
| 380 | - if ( ! empty( $controllers['posts_per_page'] ) ) { | |
| 381 | - $args['posts_per_page'] = intval( $controllers['posts_per_page'] ); | |
| 382 | - } | |
| 383 | - if ( ! empty( $controllers['columns'] ) ) { | |
| 384 | - $args['columns'] = absint( $controllers['columns'] ); | |
| 385 | - } | |
| 386 | - if ( ! empty( $controllers['orderby'] ) ) { | |
| 387 | - $args['orderby'] = $controllers['orderby']; | |
| 388 | - } | |
| 389 | - if ( ! empty( $controllers['order'] ) ) { | |
| 390 | - $args['order'] = $controllers['order']; | |
| 391 | - } | |
| 392 | - return $args; | |
| 393 | - } | |
| 394 | - | |
| 395 | - /** | |
| 396 | - * Elementor Edit mode script | |
| 397 | - * | |
| 398 | - * @return void | |
| 399 | - */ | |
| 400 | - public function editor_script() { | |
| 401 | - if ( ! $this->is_edit_mode() ) { | |
| 402 | - return; | |
| 403 | - } | |
| 404 | - ?> | |
| 405 | - <script> | |
| 406 | - <?php if ( rtsb()->has_pro() ) { ?> | |
| 407 | - setTimeout( function (){ | |
| 408 | - window.rtsbCountdownApply(); | |
| 409 | - }, 1000 ); | |
| 410 | - <?php } ?> | |
| 411 | - </script> | |
| 412 | - <?php | |
| 413 | - } | |
| 414 | - | |
| 415 | - /** | |
| 416 | - * Render Function | |
| 417 | - * | |
| 418 | - * @return void | |
| 419 | - */ | |
| 420 | - protected function render() { | |
| 421 | - global $product, $post; | |
| 422 | - $data = $this->template_data_arg(); | |
| 423 | - if ( empty( $data['template'] ) ) { | |
| 424 | - return; | |
| 425 | - } | |
| 426 | - $_product = $product; | |
| 427 | - $product = Fns::get_product(); | |
| 428 | - $controllers = $this->get_settings_for_display(); | |
| 429 | - | |
| 430 | - $controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] ); | |
| 431 | - | |
| 432 | - $this->apply_hooks(); | |
| 433 | - $this->theme_support(); | |
| 434 | - | |
| 435 | - $this->action_button_icon_modify(); | |
| 436 | - | |
| 437 | - $data['controllers'] = $controllers; | |
| 438 | - | |
| 439 | - Fns::load_template( $data['template'], $data ); | |
| 440 | - | |
| 441 | - $this->apply_hooks_set_default(); | |
| 442 | - $this->action_button_icon_set_default(); | |
| 443 | - $this->theme_support( 'render_reset' ); | |
| 444 | - | |
| 445 | - $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | |
| 446 | - if ( ! empty( $controllers['slider_activate'] ) ) { | |
| 447 | - remove_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] ); | |
| 448 | - remove_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] ); | |
| 449 | - remove_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 ); | |
| 450 | - $this->editor_slider_script(); | |
| 451 | - } | |
| 452 | - | |
| 453 | - $this->editor_script(); | |
| 454 | - $this->editor_cart_icon_script(); | |
| 455 | - | |
| 456 | - } | |
| 457 | - | |
| 458 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Main ProductDescription class. | |
| 4 | + * | |
| 5 | + * @package RadiusTheme\SB | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace RadiusTheme\SB\Abstracts; | |
| 9 | + | |
| 10 | +use RadiusTheme\SB\Helpers\Fns; | |
| 11 | +use RadiusTheme\SB\Traits\ActionBtnTraits; | |
| 12 | +use RadiusTheme\SB\Elementor\Widgets\Controls\ProductsSettings; | |
| 13 | +use RadiusTheme\SB\Elementor\Widgets\Controls\ReviewsStarSettings; | |
| 14 | +use RadiusTheme\SB\Elementor\Widgets\Controls\SliderSettings; | |
| 15 | + | |
| 16 | +// Do not allow directly accessing this file. | |
| 17 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 18 | + exit( 'This script cannot be accessed directly.' ); | |
| 19 | +} | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * Product Description class | |
| 23 | + */ | |
| 24 | +abstract class LoopWithProductSlider extends ElementorWidgetBase { | |
| 25 | + /** | |
| 26 | + * Action Button Traits. | |
| 27 | + */ | |
| 28 | + use ActionBtnTraits; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Product Loop Settings. | |
| 32 | + * | |
| 33 | + * @var object $loop_settings | |
| 34 | + */ | |
| 35 | + public $loop_settings; | |
| 36 | + /** | |
| 37 | + * Product Loop Settings. | |
| 38 | + * | |
| 39 | + * @var object $loop_settings | |
| 40 | + */ | |
| 41 | + public $has_slider = true; | |
| 42 | + /** | |
| 43 | + * Product Loop Settings. | |
| 44 | + * | |
| 45 | + * @var object $loop_settings | |
| 46 | + */ | |
| 47 | + public $has_title = true; | |
| 48 | + /** | |
| 49 | + * Product Loop Settings. | |
| 50 | + * | |
| 51 | + * @var object $loop_settings | |
| 52 | + */ | |
| 53 | + public $has_pagination = false; | |
| 54 | + /** | |
| 55 | + * This function Will overwrite by the main function' | |
| 56 | + * | |
| 57 | + * @return array | |
| 58 | + */ | |
| 59 | + abstract public function template_data_arg(); | |
| 60 | + /** | |
| 61 | + * Widget Field | |
| 62 | + * | |
| 63 | + * @return array | |
| 64 | + */ | |
| 65 | + public function widget_fields() { | |
| 66 | + | |
| 67 | + $this->loop_settings = new ProductsSettings( $this ); | |
| 68 | + $slider_control = $this->has_slider ? SliderSettings::slider_controls() : []; | |
| 69 | + $slider_style = $this->has_slider ? SliderSettings::slider_style( $this ) : []; | |
| 70 | + $heading = $this->has_title ? $this->loop_settings->heading_controls() : []; | |
| 71 | + $pagination = $this->has_pagination ? $this->loop_settings->pagination() : []; | |
| 72 | + | |
| 73 | + $fields = $this->general_section() + | |
| 74 | + $this->loop_settings->widget_icons() + | |
| 75 | + $slider_control + | |
| 76 | + $heading + | |
| 77 | + $this->loop_settings->image_section() + | |
| 78 | + $this->loop_settings->product_title() + | |
| 79 | + $this->loop_settings->product_price() + | |
| 80 | + $this->loop_settings->flash_sale() + | |
| 81 | + ReviewsStarSettings::widget_fields( $this ) + | |
| 82 | + $this->loop_settings->add_to_cart() + | |
| 83 | + $this->loop_settings->module_button_style() + | |
| 84 | + $slider_style + | |
| 85 | + $pagination; | |
| 86 | + // Fns::is_module_active('wishlist') | |
| 87 | + return apply_filters( 'rtsb/elements/elementor/rtsb_product_loop/' . $this->rtsb_base, $fields, $this ); | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * Widget Field | |
| 92 | + * | |
| 93 | + * @return array | |
| 94 | + */ | |
| 95 | + public function general_section() { | |
| 96 | + $fields = $this->loop_settings->general_section(); | |
| 97 | + if ( 'rtsb-related-product' === $this->rtsb_base ) { | |
| 98 | + unset( $fields['orderby'] ); | |
| 99 | + unset( $fields['order'] ); | |
| 100 | + } | |
| 101 | + if ( 'rtsb-products-archive' === $this->rtsb_base ) { | |
| 102 | + unset( $fields['posts_per_page'] ); | |
| 103 | + unset( $fields['columns'] ); | |
| 104 | + unset( $fields['orderby'] ); | |
| 105 | + unset( $fields['order'] ); | |
| 106 | + } | |
| 107 | + return $fields; | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Widget Field. | |
| 112 | + * | |
| 113 | + * @return void | |
| 114 | + */ | |
| 115 | + public function script_init() { | |
| 116 | + wp_dequeue_script( 'rtsb-public' ); | |
| 117 | + | |
| 118 | + wp_enqueue_style( 'swiper' ); | |
| 119 | + wp_enqueue_script( 'swiper' ); | |
| 120 | + wp_enqueue_script( 'rtsb-public' ); | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Product loop start function | |
| 125 | + * | |
| 126 | + * @return string | |
| 127 | + */ | |
| 128 | + public function product_loop_start( $html = '' ) { | |
| 129 | + $str = explode( 'products', $html ); | |
| 130 | + if ( is_array( $str ) ) { | |
| 131 | + $html = $str[0] . ' products swiper-wrapper ' . $str[1]; | |
| 132 | + } | |
| 133 | + $controllers = $this->get_settings_for_display(); | |
| 134 | + | |
| 135 | + $swiper_data = [ | |
| 136 | + // Optional parameters. | |
| 137 | + 'wrapperClass' => 'products', | |
| 138 | + 'slideClass' => 'product', | |
| 139 | + 'slidesPerView' => 4, | |
| 140 | + 'slidesPerGroup' => 3, | |
| 141 | + 'spaceBetween' => 15, | |
| 142 | + 'loop' => false, | |
| 143 | + 'autoplay' => false, | |
| 144 | + ]; | |
| 145 | + $classes = []; | |
| 146 | + if ( ! empty( $controllers['columns'] ) ) { | |
| 147 | + $swiper_data['slidesPerView'] = absint( $controllers['columns'] ); | |
| 148 | + $swiper_data['slidesPerGroup'] = absint( $controllers['columns'] ); | |
| 149 | + } | |
| 150 | + if ( ! empty( $controllers['space_between'] ) ) { | |
| 151 | + $swiper_data['spaceBetween'] = absint( $controllers['space_between'] ); | |
| 152 | + } | |
| 153 | + if ( ! empty( $controllers['loop'] ) ) { | |
| 154 | + $swiper_data['loop'] = boolval( $controllers['loop'] ); | |
| 155 | + } | |
| 156 | + if ( ! empty( $controllers['autoplay'] ) ) { | |
| 157 | + $swiper_data['autoplay']['delay'] = absint( $controllers['autoplay_delay'] ); | |
| 158 | + $swiper_data['autoplay']['pauseOnMouseEnter'] = boolval( $controllers['pauseon_mouseenter'] ); | |
| 159 | + $swiper_data['autoplay']['disableOnInteraction'] = false; | |
| 160 | + } | |
| 161 | + if ( ! empty( $controllers['speed'] ) ) { | |
| 162 | + $swiper_data['speed'] = absint( $controllers['speed'] ); | |
| 163 | + } | |
| 164 | + if ( ! empty( $controllers['show_arrows'] ) ) { | |
| 165 | + $swiper_data['navigation'] = [ | |
| 166 | + 'nextEl' => '.button-right', | |
| 167 | + 'prevEl' => '.button-left', | |
| 168 | + ]; | |
| 169 | + $classes[] = 'has-navigation'; | |
| 170 | + } | |
| 171 | + if ( ! empty( $controllers['show_dots'] ) ) { | |
| 172 | + $swiper_data['pagination'] = [ | |
| 173 | + 'el' => '.rtsb-slider-pagination', | |
| 174 | + 'type' => 'bullets', | |
| 175 | + 'clickable' => true, | |
| 176 | + ]; | |
| 177 | + $classes[] = 'has-dots'; | |
| 178 | + } | |
| 179 | + | |
| 180 | + $data = [ | |
| 181 | + 'template' => 'global/slider-header', | |
| 182 | + 'controllers' => $controllers, | |
| 183 | + 'swiper_json_data' => wp_json_encode( $swiper_data ), | |
| 184 | + 'classes' => $classes, | |
| 185 | + ]; | |
| 186 | + $new = Fns::load_template( $data['template'], $data, true ); | |
| 187 | + $html = $new . $html; | |
| 188 | + return $html; | |
| 189 | + } | |
| 190 | + /** | |
| 191 | + * Product loop start function | |
| 192 | + * | |
| 193 | + * @return string | |
| 194 | + */ | |
| 195 | + public function product_loop_end( $html ) { | |
| 196 | + $controllers = $this->get_settings_for_display(); | |
| 197 | + $data = [ | |
| 198 | + 'template' => 'global/slider-footer', | |
| 199 | + 'controllers' => $controllers, | |
| 200 | + 'left_arrow' => Fns::icons_manager( $controllers['left_arrow_icon'] ), | |
| 201 | + 'right_arrow' => Fns::icons_manager( $controllers['right_arrow_icon'] ), | |
| 202 | + ]; | |
| 203 | + $new = Fns::load_template( $data['template'], $data, true ); | |
| 204 | + $html = $html . $new; | |
| 205 | + return $html; | |
| 206 | + } | |
| 207 | + /** | |
| 208 | + * Product loop start function | |
| 209 | + * | |
| 210 | + * @return string | |
| 211 | + */ | |
| 212 | + public function post_class( $classes ) { | |
| 213 | + $classes[] = 'swiper-slide'; | |
| 214 | + return $classes; | |
| 215 | + } | |
| 216 | + /** | |
| 217 | + * Product loop start function | |
| 218 | + * | |
| 219 | + * @return string | |
| 220 | + */ | |
| 221 | + public function is_rtsb_wrap_based_on_theme() { | |
| 222 | + $theme_list = apply_filters( 'rtsb/products/innner/wrapper/basedon/themes', [ | |
| 223 | + 'twentytwentyone', | |
| 224 | + 'twentytwentytwo', | |
| 225 | + 'twentytwentythree', | |
| 226 | + 'storefront', | |
| 227 | + 'hello-elementor', | |
| 228 | + 'astra' | |
| 229 | + ], rtsb()->current_theme ); | |
| 230 | + if ( in_array( rtsb()->current_theme, $theme_list, true) ) { | |
| 231 | + return true; | |
| 232 | + } | |
| 233 | + return false; | |
| 234 | + } | |
| 235 | + /** | |
| 236 | + * Image Wrapper. | |
| 237 | + * | |
| 238 | + * @return void | |
| 239 | + */ | |
| 240 | + public function image_wrapper() { | |
| 241 | + | |
| 242 | + if( ! $this->is_rtsb_wrap_based_on_theme() ){ | |
| 243 | + return; | |
| 244 | + } | |
| 245 | + ?> | |
| 246 | + <div class="rtsb-image-wrapper"> | |
| 247 | + <?php | |
| 248 | + } | |
| 249 | + /** | |
| 250 | + * Image Wrapper. | |
| 251 | + * | |
| 252 | + * @return void | |
| 253 | + */ | |
| 254 | + public function div_close() { | |
| 255 | + if( ! $this->is_rtsb_wrap_based_on_theme() ){ | |
| 256 | + return; | |
| 257 | + } | |
| 258 | + ?> | |
| 259 | + </div> | |
| 260 | + <?php | |
| 261 | + } | |
| 262 | + /** | |
| 263 | + * Image Wrapper. | |
| 264 | + * | |
| 265 | + * @return void | |
| 266 | + */ | |
| 267 | + public function product_content_wrapper() { | |
| 268 | + if( ! $this->is_rtsb_wrap_based_on_theme() ){ | |
| 269 | + return; | |
| 270 | + } | |
| 271 | + ?> | |
| 272 | + <div class="rtsb-product-content"> | |
| 273 | + <?php | |
| 274 | + } | |
| 275 | + | |
| 276 | + /** | |
| 277 | + * Apply hooks function. | |
| 278 | + * | |
| 279 | + * @return void | |
| 280 | + */ | |
| 281 | + public function apply_hooks() { | |
| 282 | + $controllers = $this->get_settings_for_display(); | |
| 283 | + | |
| 284 | + if ( empty( $controllers['show_rating'] ) ) { | |
| 285 | + remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); | |
| 286 | + add_filter( 'woocommerce_product_get_rating_html', '__return_false' ); | |
| 287 | + } | |
| 288 | + if ( empty( $controllers['show_flash_sale'] ) ) { | |
| 289 | + add_filter( 'woocommerce_sale_flash', '__return_false' ); | |
| 290 | + } | |
| 291 | + if ( ! empty( $controllers['slider_activate'] ) ) { | |
| 292 | + add_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] ); | |
| 293 | + add_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] ); | |
| 294 | + add_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 ); | |
| 295 | + $this->script_init(); | |
| 296 | + } | |
| 297 | + | |
| 298 | + if ( class_exists('WooProductVariationSwatches') ) { | |
| 299 | + remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5); | |
| 300 | + remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 20); | |
| 301 | + remove_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 8); | |
| 302 | + remove_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 12); | |
| 303 | + } | |
| 304 | + | |
| 305 | + // Remove Action Button | |
| 306 | + add_filter( 'rtsb/module/wishlist/show_button', '__return_false' ); | |
| 307 | + add_filter( 'rtsb/module/quick_view/show_button', '__return_false' ); | |
| 308 | + add_filter( 'rtsb/module/compare/show_button', '__return_false' ); | |
| 309 | + | |
| 310 | + // Default Link remove. | |
| 311 | + remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); | |
| 312 | + remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 ); | |
| 313 | + | |
| 314 | + // Image Wrapper open. | |
| 315 | + add_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 ); | |
| 316 | + | |
| 317 | + // Image link. | |
| 318 | + add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 ); | |
| 319 | + add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 ); | |
| 320 | + // Image link end. | |
| 321 | + | |
| 322 | + // Title Link. | |
| 323 | + add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 ); | |
| 324 | + add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 ); | |
| 325 | + // Title Link end. | |
| 326 | + | |
| 327 | + // Image Wrapper close. | |
| 328 | + add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 ); | |
| 329 | + // Content Wrapper Open. | |
| 330 | + add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 ); | |
| 331 | + // Content Wrapper Close. | |
| 332 | + add_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 ); | |
| 333 | + | |
| 334 | + } | |
| 335 | + /** | |
| 336 | + * Apply hooks function. | |
| 337 | + * | |
| 338 | + * @return void | |
| 339 | + */ | |
| 340 | + public function apply_hooks_set_default() { | |
| 341 | + | |
| 342 | + // Default Link re active. | |
| 343 | + add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); | |
| 344 | + add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 ); | |
| 345 | + | |
| 346 | + // Image Wrapper open. | |
| 347 | + remove_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 ); | |
| 348 | + | |
| 349 | + // Image link. | |
| 350 | + remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 ); | |
| 351 | + remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 ); | |
| 352 | + // Image link end. | |
| 353 | + | |
| 354 | + // Title Link. | |
| 355 | + remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 ); | |
| 356 | + remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 ); | |
| 357 | + // Title Link End. | |
| 358 | + | |
| 359 | + // Image Wrapper close. | |
| 360 | + remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 ); | |
| 361 | + | |
| 362 | + // Content Wrapper Open. | |
| 363 | + remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 ); | |
| 364 | + // Content Wrapper Close. | |
| 365 | + remove_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 ); | |
| 366 | + | |
| 367 | + // Remove Action Button. | |
| 368 | + remove_filter( 'rtsb/module/wishlist/show_button', '__return_false' ); | |
| 369 | + remove_filter( 'rtsb/module/quick_view/show_button', '__return_false' ); | |
| 370 | + remove_filter( 'rtsb/module/compare/show_button', '__return_false' ); | |
| 371 | + | |
| 372 | + } | |
| 373 | + /** | |
| 374 | + * Related Product Args function' | |
| 375 | + * | |
| 376 | + * @param [type] $args argument. | |
| 377 | + * @return array | |
| 378 | + */ | |
| 379 | + public function products_args( $args ) { | |
| 380 | + $controllers = $this->get_settings_for_display(); | |
| 381 | + if ( ! empty( $controllers['posts_per_page'] ) ) { | |
| 382 | + $args['posts_per_page'] = intval( $controllers['posts_per_page'] ); | |
| 383 | + } | |
| 384 | + if ( ! empty( $controllers['columns'] ) ) { | |
| 385 | + $args['columns'] = absint( $controllers['columns'] ); | |
| 386 | + } | |
| 387 | + if ( ! empty( $controllers['orderby'] ) ) { | |
| 388 | + $args['orderby'] = $controllers['orderby']; | |
| 389 | + } | |
| 390 | + if ( ! empty( $controllers['order'] ) ) { | |
| 391 | + $args['order'] = $controllers['order']; | |
| 392 | + } | |
| 393 | + return $args; | |
| 394 | + } | |
| 395 | + | |
| 396 | + /** | |
| 397 | + * Render Function | |
| 398 | + * | |
| 399 | + * @return void | |
| 400 | + */ | |
| 401 | + protected function render() { | |
| 402 | + global $product, $post; | |
| 403 | + $data = $this->template_data_arg(); | |
| 404 | + if ( empty( $data['template'] ) ) { | |
| 405 | + return; | |
| 406 | + } | |
| 407 | + $_product = $product; | |
| 408 | + $product = Fns::get_product(); | |
| 409 | + $controllers = $this->get_settings_for_display(); | |
| 410 | + | |
| 411 | + $controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] ); | |
| 412 | + | |
| 413 | + $this->apply_hooks(); | |
| 414 | + $this->theme_support(); | |
| 415 | + | |
| 416 | + $this->action_button_icon_modify(); | |
| 417 | + | |
| 418 | + $data['controllers'] = $controllers; | |
| 419 | + | |
| 420 | + Fns::load_template( $data['template'], $data ); | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + $this->apply_hooks_set_default(); | |
| 425 | + $this->action_button_icon_set_default(); | |
| 426 | + $this->theme_support( 'render_reset' ); | |
| 427 | + | |
| 428 | + $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | |
| 429 | + if ( ! empty( $controllers['slider_activate'] ) ) { | |
| 430 | + remove_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] ); | |
| 431 | + remove_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] ); | |
| 432 | + remove_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 ); | |
| 433 | + $this->editor_slider_script(); | |
| 434 | + } | |
| 435 | + | |
| 436 | + $this->editor_cart_icon_script(); | |
| 437 | + | |
| 438 | + } | |
| 439 | + | |
| 440 | +} | |