| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main ProductImages class. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Elementor\Widgets\Single; |
| 9 |
|
| 10 |
use RadiusTheme\SB\Helpers\Fns; |
| 11 |
use RadiusTheme\SB\Abstracts\ElementorWidgetBase; |
| 12 |
use RadiusTheme\SB\Elementor\Widgets\Controls\ProductImagesSettings; |
| 13 |
|
| 14 |
// Do not allow directly accessing this file. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit( 'This script cannot be accessed directly.' ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Product Images class |
| 21 |
*/ |
| 22 |
class ProductImages extends ElementorWidgetBase { |
| 23 |
/** |
| 24 |
* Construct function |
| 25 |
* |
| 26 |
* @param array $data default array. |
| 27 |
* @param mixed $args default arg. |
| 28 |
*/ |
| 29 |
public function __construct( $data = [], $args = null ) { |
| 30 |
$this->rtsb_name = esc_html__( 'Product Images', 'shopbuilder' ); |
| 31 |
$this->rtsb_base = 'rtsb-product-image'; |
| 32 |
parent::__construct( $data, $args ); |
| 33 |
add_action( 'wp_footer', 'woocommerce_photoswipe' ); |
| 34 |
$this->the_hooks(); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Widget Field |
| 39 |
* |
| 40 |
* @return array |
| 41 |
*/ |
| 42 |
public function widget_fields() { |
| 43 |
$fields = ProductImagesSettings::widget_fields( $this ); |
| 44 |
return apply_filters( 'rtsb/elements/elementor/single/' . $this->rtsb_base, $fields, $this ); |
| 45 |
} |
| 46 |
/** |
| 47 |
* Widget Field. |
| 48 |
* |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public function editor_scripts() { |
| 52 |
?> |
| 53 |
<script> |
| 54 |
/* |
| 55 |
* Initialize all galleries on page. |
| 56 |
*/ |
| 57 |
jQuery( '.woocommerce-product-gallery' ).each( function() { |
| 58 |
jQuery( this ).trigger( 'wc-product-gallery-before-init', [ this, wc_single_product_params ] ); |
| 59 |
setTimeout( function(){ |
| 60 |
jQuery(this).wc_product_gallery(wc_single_product_params); |
| 61 |
}, 1000 ); |
| 62 |
|
| 63 |
jQuery( this ).trigger( 'wc-product-gallery-after-init', [ this, wc_single_product_params ] ); |
| 64 |
} ); |
| 65 |
<?php if ( function_exists( 'rtwpvg' ) ) { ?> |
| 66 |
setTimeout( function(){ |
| 67 |
jQuery('.rtsb-product-images .rtwpvg-wrapper').rtWpVGallery(); |
| 68 |
}, 1000 ); |
| 69 |
<?php } ?> |
| 70 |
|
| 71 |
jQuery(document).ready(function ($) { |
| 72 |
setTimeout(function () { |
| 73 |
const zoomIcon = $('.rtsb-product-images').attr('data-zoom-icon'); |
| 74 |
if (!zoomIcon) { |
| 75 |
$('.rtsb-product-images') |
| 76 |
.find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger') |
| 77 |
.remove(); |
| 78 |
} |
| 79 |
$('.rtsb-product-images') |
| 80 |
.find('.woocommerce-product-gallery__trigger,.rtwpvg-trigger') |
| 81 |
.html(zoomIcon); |
| 82 |
}, 50); |
| 83 |
}); |
| 84 |
</script> |
| 85 |
<?php |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Widget Field. |
| 90 |
* |
| 91 |
* @param array $control Control. |
| 92 |
* |
| 93 |
* @return void |
| 94 |
*/ |
| 95 |
public function the_hooks( $control = null ) { |
| 96 |
if ( ! $control ) { |
| 97 |
return; |
| 98 |
} |
| 99 |
add_filter( |
| 100 |
'woocommerce_product_thumbnails_columns', |
| 101 |
function( $col ) { |
| 102 |
$col = 0; |
| 103 |
return $col; |
| 104 |
} |
| 105 |
); |
| 106 |
if ( empty( $control['show_zoom'] ) ) { |
| 107 |
add_filter( 'rtwpvg_trigger_icon', '__return_false' ); |
| 108 |
} |
| 109 |
if ( empty( $control['show_thumbnails'] ) ) { |
| 110 |
add_filter( 'rtwpvg_show_product_thumbnail_slider', '__return_false' ); |
| 111 |
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 ); |
| 112 |
} |
| 113 |
} |
| 114 |
/** |
| 115 |
* Render Function |
| 116 |
* |
| 117 |
* @return void |
| 118 |
*/ |
| 119 |
protected function render() { |
| 120 |
global $product, $post; |
| 121 |
$_product = $product; |
| 122 |
$product = Fns::get_product(); |
| 123 |
$controllers = $this->get_settings_for_display(); |
| 124 |
|
| 125 |
$this->theme_support(); |
| 126 |
|
| 127 |
$controllers['lightbox_icon'] = Fns::icons_manager( $controllers['lightbox_icon'] ); |
| 128 |
$data = [ |
| 129 |
'template' => 'elementor/single-product/product-images', |
| 130 |
'controllers' => $controllers, |
| 131 |
]; |
| 132 |
$this->the_hooks( $controllers ); |
| 133 |
|
| 134 |
Fns::load_template( $data['template'], $data ); |
| 135 |
|
| 136 |
if ( $this->is_edit_mode() ) { |
| 137 |
$this->editor_scripts(); |
| 138 |
} |
| 139 |
$this->theme_support( 'render_reset' ); |
| 140 |
$product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 141 |
} |
| 142 |
|
| 143 |
} |
| 144 |
|