| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main ProductDescription 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\AddToCartSettings; |
| 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 Description class |
| 21 |
*/ |
| 22 |
class ProductAddToCart 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 add to cart', 'shopbuilder' ); |
| 31 |
$this->rtsb_base = 'rtsb-product-add-to-cart'; |
| 32 |
parent::__construct( $data, $args ); |
| 33 |
} |
| 34 |
/** |
| 35 |
* Widget Field |
| 36 |
* |
| 37 |
* @return array |
| 38 |
*/ |
| 39 |
public function widget_fields() { |
| 40 |
return AddToCartSettings::widget_fields( $this ); |
| 41 |
} |
| 42 |
/** |
| 43 |
* Set Widget Keyword. |
| 44 |
* |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
public function get_keywords() { |
| 48 |
return [ 'Cart' ] + parent::get_keywords(); |
| 49 |
} |
| 50 |
/** |
| 51 |
* Widget Field. |
| 52 |
* |
| 53 |
* @param array $controllers Control. |
| 54 |
* |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function the_hooks( $controllers = null ) { |
| 58 |
if ( ! $controllers ) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
add_filter( 'rtsb/module/flash_sale_countdown/show_counter', '__return_false', 99 ); |
| 63 |
$product = Fns::get_product(); |
| 64 |
$is_visible_qty = Fns::is_visible_qty_input( $product ); |
| 65 |
if ( ! empty( $controllers['quantity_style'] ) && $is_visible_qty ) { |
| 66 |
if ( in_array( $controllers['quantity_style'], [ 'style-1', 'style-2' ] ) ) { |
| 67 |
add_action( |
| 68 |
'woocommerce_before_quantity_input_field', |
| 69 |
function () use ( $controllers ) { |
| 70 |
?> |
| 71 |
<!-- Quantity Wrapper Start --> |
| 72 |
<div class="rtsb-quantity-box-group rtsb-quantity-box-group-<?php echo esc_attr( $controllers['quantity_style'] ); ?>"> |
| 73 |
<button type="button" class="rtsb-quantity-btn rtsb-quantity-minus"> |
| 74 |
<?php |
| 75 |
echo wp_kses( |
| 76 |
$controllers['decrement_icon_html'], |
| 77 |
[ |
| 78 |
'i' => [ |
| 79 |
'class' => [], |
| 80 |
'aria-hidden' => [], |
| 81 |
], |
| 82 |
] |
| 83 |
); |
| 84 |
?> |
| 85 |
</button> |
| 86 |
<?php |
| 87 |
} |
| 88 |
); |
| 89 |
add_action( |
| 90 |
'woocommerce_after_quantity_input_field', |
| 91 |
function () use ( $controllers ) { |
| 92 |
?> |
| 93 |
<button type="button" class="rtsb-quantity-btn rtsb-quantity-plus"> |
| 94 |
<?php |
| 95 |
echo wp_kses( |
| 96 |
$controllers['increment_icon_html'], |
| 97 |
[ |
| 98 |
'i' => [ |
| 99 |
'class' => [], |
| 100 |
'aria-hidden' => [], |
| 101 |
], |
| 102 |
] |
| 103 |
); |
| 104 |
?> |
| 105 |
</button> |
| 106 |
</div> |
| 107 |
<!-- Quantity Wrapper End --> |
| 108 |
<?php |
| 109 |
} |
| 110 |
); |
| 111 |
} |
| 112 |
if ( in_array( $controllers['quantity_style'], [ 'style-3', 'style-4' ] ) && $is_visible_qty ) { |
| 113 |
add_action( |
| 114 |
'woocommerce_before_quantity_input_field', |
| 115 |
function () use ( $controllers ) { |
| 116 |
$inner_border = ! empty( $controllers['show_inner_border'] ) ? 'show-inner-border' : ''; |
| 117 |
?> |
| 118 |
<!-- Quantity Wrapper Start --> |
| 119 |
<div class="rtsb-quantity-box-group rtsb-quantity-box-group-<?php echo esc_attr( $controllers['quantity_style'] . ' ' . $inner_border ); ?>"> |
| 120 |
<div class="rtsb-qty-btns-group"> |
| 121 |
<button type="button" class="rtsb-quantity-btn rtsb-quantity-plus"> |
| 122 |
<?php |
| 123 |
echo wp_kses( |
| 124 |
$controllers['increment_icon_html'], |
| 125 |
[ |
| 126 |
'i' => [ |
| 127 |
'class' => [], |
| 128 |
'aria-hidden' => [], |
| 129 |
], |
| 130 |
] |
| 131 |
); |
| 132 |
?> |
| 133 |
</button> |
| 134 |
<button type="button" class="rtsb-quantity-btn rtsb-quantity-minus"> |
| 135 |
<?php |
| 136 |
echo wp_kses( |
| 137 |
$controllers['decrement_icon_html'], |
| 138 |
[ |
| 139 |
'i' => [ |
| 140 |
'class' => [], |
| 141 |
'aria-hidden' => [], |
| 142 |
], |
| 143 |
] |
| 144 |
); |
| 145 |
?> |
| 146 |
</button> |
| 147 |
</div> |
| 148 |
<?php |
| 149 |
} |
| 150 |
); |
| 151 |
add_action( |
| 152 |
'woocommerce_after_quantity_input_field', |
| 153 |
function () { |
| 154 |
?> |
| 155 |
</div> |
| 156 |
<!-- Quantity Wrapper End --> |
| 157 |
<?php |
| 158 |
} |
| 159 |
); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
if ( $this->is_edit_mode() ) { |
| 164 |
if ( class_exists( Rtwpvs\Controllers\Hooks::class ) ) { |
| 165 |
remove_filter( 'woocommerce_ajax_variationX_threshold', [ Rtwpvs\Controllers\Hooks::class, 'ajax_variation_threshold' ], 99 ); |
| 166 |
} |
| 167 |
|
| 168 |
add_filter( |
| 169 |
'woocommerce_ajax_variation_threshold', |
| 170 |
function () { |
| 171 |
return 1; |
| 172 |
}, |
| 173 |
99 |
| 174 |
); |
| 175 |
|
| 176 |
} |
| 177 |
} |
| 178 |
/** |
| 179 |
* Render Function |
| 180 |
* |
| 181 |
* @return void |
| 182 |
*/ |
| 183 |
protected function render() { |
| 184 |
global $product; |
| 185 |
$_product = $product; |
| 186 |
$product = Fns::get_product(); |
| 187 |
$controllers = $this->get_settings_for_display(); |
| 188 |
$controllers['increment_icon_html'] = Fns::icons_manager( $controllers['increment_icon'] ); |
| 189 |
$controllers['decrement_icon_html'] = Fns::icons_manager( $controllers['decrement_icon'] ); |
| 190 |
$controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] ); |
| 191 |
$add_to_cart_visibility = rtsb()->has_pro() && Fns::is_guest_feature_disabled( 'hide_add_to_cart', '' ); |
| 192 |
$controllers['visibility'] = $add_to_cart_visibility ? ' rtsb-not-visible' : ' rtsb-is-visible'; |
| 193 |
|
| 194 |
$this->the_hooks( $controllers ); |
| 195 |
$this->theme_support(); |
| 196 |
|
| 197 |
$data = [ |
| 198 |
'template' => 'elementor/single-product/add-to-cart', |
| 199 |
'controllers' => $controllers, |
| 200 |
'product_type' => $product ? $product->get_type() : '', |
| 201 |
]; |
| 202 |
|
| 203 |
Fns::load_template( $data['template'], $data ); |
| 204 |
|
| 205 |
$this->editor_cart_icon_script(); |
| 206 |
add_filter( 'rtsb/module/flash_sale_countdown/show_counter', '__return_true', 99 ); |
| 207 |
$this->theme_support( 'render_reset' ); |
| 208 |
|
| 209 |
$product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 210 |
} |
| 211 |
} |
| 212 |
|