PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.2.2
ShopBuilder – WooCommerce Builder For Elementor v2.2.2
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Elementor / Widgets / Single / ProductAddToCart.php

ProductAddToCart.php in ShopBuilder – WooCommerce Builder For Elementor 2.2.2, at app/Elementor/Widgets/Single/ProductAddToCart.php

180 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 Fns::print_html( $controllers['decrement_icon_html'], true );
76 ?>
77 </button>
78 <?php
79 }
80 );
81 add_action(
82 'woocommerce_after_quantity_input_field',
83 function () use ( $controllers ) {
84 ?>
85 <button type="button" class="rtsb-quantity-btn rtsb-quantity-plus">
86 <?php
87 Fns::print_html( $controllers['increment_icon_html'], true );
88 ?>
89 </button>
90 </div>
91 <!-- Quantity Wrapper End -->
92 <?php
93 }
94 );
95 }
96 if ( in_array( $controllers['quantity_style'], [ 'style-3', 'style-4' ] ) && $is_visible_qty ) {
97 add_action(
98 'woocommerce_before_quantity_input_field',
99 function () use ( $controllers ) {
100 $inner_border = ! empty( $controllers['show_inner_border'] ) ? 'show-inner-border' : '';
101 ?>
102 <!-- Quantity Wrapper Start -->
103 <div class="rtsb-quantity-box-group rtsb-quantity-box-group-<?php echo esc_attr( $controllers['quantity_style'] . ' ' . $inner_border ); ?>">
104 <div class="rtsb-qty-btns-group">
105 <button type="button" class="rtsb-quantity-btn rtsb-quantity-plus">
106 <?php
107 Fns::print_html( $controllers['increment_icon_html'], true );
108 ?>
109 </button>
110 <button type="button" class="rtsb-quantity-btn rtsb-quantity-minus">
111 <?php
112 Fns::print_html( $controllers['decrement_icon_html'], true );
113 ?>
114 </button>
115 </div>
116 <?php
117 }
118 );
119 add_action(
120 'woocommerce_after_quantity_input_field',
121 function () {
122 ?>
123 </div>
124 <!-- Quantity Wrapper End -->
125 <?php
126 }
127 );
128 }
129 }
130
131 if ( $this->is_edit_mode() ) {
132 if ( class_exists( Rtwpvs\Controllers\Hooks::class ) ) {
133 remove_filter( 'woocommerce_ajax_variationX_threshold', [ Rtwpvs\Controllers\Hooks::class, 'ajax_variation_threshold' ], 99 );
134 }
135
136 add_filter(
137 'woocommerce_ajax_variation_threshold',
138 function () {
139 return 1;
140 },
141 99
142 );
143
144 }
145 }
146 /**
147 * Render Function
148 *
149 * @return void
150 */
151 protected function render() {
152 global $product;
153 $_product = $product;
154 $product = Fns::get_product();
155 $controllers = $this->get_settings_for_display();
156 $controllers['increment_icon_html'] = Fns::icons_manager( $controllers['increment_icon'] );
157 $controllers['decrement_icon_html'] = Fns::icons_manager( $controllers['decrement_icon'] );
158 $controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] );
159 $add_to_cart_visibility = rtsb()->has_pro() && Fns::is_guest_feature_disabled( 'hide_add_to_cart', '' );
160 $controllers['visibility'] = $add_to_cart_visibility ? ' rtsb-not-visible' : ' rtsb-is-visible';
161
162 $this->the_hooks( $controllers );
163 $this->theme_support();
164
165 $data = [
166 'template' => 'elementor/single-product/add-to-cart',
167 'controllers' => $controllers,
168 'product_type' => $product ? $product->get_type() : '',
169 ];
170
171 Fns::load_template( $data['template'], $data );
172
173 $this->editor_cart_icon_script();
174 add_filter( 'rtsb/module/flash_sale_countdown/show_counter', '__return_true', 99 );
175 $this->theme_support( 'render_reset' );
176
177 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
178 }
179 }
180