PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 3.6.0
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v3.6.0
5.5.4 5.5.3 3.1.0 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.6.0 3.7.0 3.8.0 3.8.1 3.8.2 3.8.3 4.0.0 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 All 79 releases
copy-the-code / classes / elementor / widgets / coupon / widget.php

widget.php in Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code 3.6.0, at classes/elementor/widgets/coupon/widget.php

394 lines 12.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Elementor Coupon Block
5 *
6 * @package Copy the Code
7 * @since 3.1.0
8 */
9 namespace CopyTheCode\Elementor\Block;
10
11 use Elementor\Utils ;
12 use CopyTheCode\Helpers ;
13 use Elementor\Widget_Base ;
14 use Elementor\Controls_Manager ;
15 /**
16 * Coupon Block
17 *
18 * @since 3.1.0
19 */
20 class Coupon extends Widget_Base
21 {
22 /**
23 * Constructor
24 *
25 * @param array $data
26 * @param array $args
27 *
28 * @since 3.1.0
29 */
30 public function __construct( $data = array(), $args = null )
31 {
32 parent::__construct( $data, $args );
33 // Block.
34 wp_enqueue_style(
35 'ctc-el-coupon',
36 COPY_THE_CODE_URI . 'classes/elementor/widgets/coupon/style.css',
37 [],
38 COPY_THE_CODE_VER,
39 'all'
40 );
41 wp_enqueue_script(
42 'ctc-el-coupon',
43 COPY_THE_CODE_URI . 'classes/elementor/widgets/coupon/script.js',
44 [],
45 COPY_THE_CODE_VER,
46 true
47 );
48 }
49
50 /**
51 * Get style dependencies
52 */
53 public function get_style_depends()
54 {
55 return [ 'ctc-el-coupon' ];
56 }
57
58 /**
59 * Get script dependencies
60 */
61 public function get_script_depends()
62 {
63 return [ 'ctc-el-coupon' ];
64 }
65
66 /**
67 * Get name
68 */
69 public function get_name()
70 {
71 return 'ctc_coupon';
72 }
73
74 /**
75 * Get title
76 */
77 public function get_title()
78 {
79 return esc_html__( 'Coupon Code', 'copy-the-code' );
80 }
81
82 /**
83 * Get icon
84 */
85 public function get_icon()
86 {
87 return 'eicon-cart-solid';
88 }
89
90 /**
91 * Get categories
92 */
93 public function get_categories()
94 {
95 return Helpers::get_categories();
96 }
97
98 /**
99 * Get keywords
100 */
101 public function get_keywords()
102 {
103 return Helpers::get_keywords( [
104 'coupon',
105 'offer',
106 'coupon',
107 'sale'
108 ] );
109 }
110
111 /**
112 * Render
113 */
114 public function render()
115 {
116 $image = $this->get_settings_for_display( 'image' );
117 $heading = $this->get_settings_for_display( 'heading' );
118 $description = $this->get_settings_for_display( 'description' );
119 $slide_button_text = $this->get_settings_for_display( 'slide_button_text' );
120 $coupon_code = $this->get_settings_for_display( 'coupon_code' );
121 $button_link = $this->get_settings_for_display( 'button_link' );
122 $link_target = $this->get_settings_for_display( 'link_target' );
123 $details = $this->get_settings_for_display( 'details' );
124 $toggle_details = $this->get_settings_for_display( 'toggle_details' );
125 $button_text = $this->get_settings_for_display( 'button_text' );
126 $button_text_copied = $this->get_settings_for_display( 'button_text_copied' );
127 $show_icon = $this->get_settings_for_display( 'show_icon' );
128 $icon_direction = $this->get_settings_for_display( 'icon_direction' );
129 $display_slide_button = $this->get_settings_for_display( 'display_slide_button' );
130 $clicked = ( 'yes' === $display_slide_button ? '' : ' ctc-coupon-clicked' );
131 ?>
132 <div class="ctc-block ctc-coupon <?php
133 echo $clicked ;
134 ?>">
135 <div class="ctc-coupon-header">
136 <?php
137
138 if ( $image['url'] ) {
139 ?>
140 <div class="ctc-coupon-image">
141 <img src="<?php
142 echo esc_url( $image['url'] ) ;
143 ?>" alt="<?php
144 echo esc_attr( $heading ) ;
145 ?>">
146 </div>
147 <?php
148 }
149
150 ?>
151 <div class="ctc-coupon-headings">
152 <h3 class="ctc-coupon-heading"><?php
153 echo esc_html( $heading ) ;
154 ?></h3>
155
156 <?php
157
158 if ( $description ) {
159 ?>
160 <div class="ctc-coupon-description"><?php
161 echo wp_kses_post( wpautop( $description ) ) ;
162 ?></div>
163 <?php
164 }
165
166 ?>
167
168 </div>
169 <div class="ctc-coupon-cta">
170 <span class="ctc-coupon-code"><?php
171 echo esc_html( $coupon_code ) ;
172 ?></span>
173
174 <?php
175
176 if ( 'yes' === $display_slide_button ) {
177 ?>
178 <a href="<?php
179 echo esc_url( $button_link['url'] ) ;
180 ?>" target="<?php
181 echo esc_attr( $link_target ) ;
182 ?>" class="ctc-coupon-link"><?php
183 echo esc_html( $slide_button_text ) ;
184 ?></a>
185 <?php
186 }
187
188 ?>
189
190 <?php
191 echo Helpers::get_copy_button( [
192 'as_raw' => 'no',
193 'copy_button_text' => $button_text,
194 'copy_button_text_copied' => $button_text_copied,
195 'icon_direction' => $icon_direction,
196 'show_icon' => $show_icon,
197 ] ) ;
198 ?>
199 <textarea class="ctc-copy-content" style="display: none;"><?php
200 echo esc_html( $coupon_code ) ;
201 ?></textarea>
202 </div>
203 </div>
204 <?php
205
206 if ( $details ) {
207 ?>
208 <div class="ctc-coupon-details">
209 <?php
210 $toggle_details_class = ( 'yes' === $toggle_details ? 'ctc-toggle-details' : '' );
211 if ( 'yes' === $toggle_details ) {
212 echo '<a href="#" class="ctc-coupon-toggle-link">Show Details</a>' ;
213 }
214 echo '<div class="ctc-details-content ' . $toggle_details_class . '">' . wp_kses_post( wpautop( $details ) ) . '</div>' ;
215 ?>
216 </div>
217 <?php
218 }
219
220 ?>
221 </div>
222 <?php
223 }
224
225 /**
226 * Register controls
227 */
228 protected function _register_controls()
229 {
230 $this->start_controls_section( 'image_section', [
231 'label' => esc_html__( 'Coupon Image', 'copy-the-code' ),
232 ] );
233 $this->add_control( 'image', [
234 'label' => esc_html__( 'Coupon Image', 'copy-the-code' ),
235 'type' => Controls_Manager::MEDIA,
236 'default' => [
237 'url' => Utils::get_placeholder_image_src(),
238 ],
239 ] );
240 $this->end_controls_section();
241 $this->start_controls_section( 'heading_section', [
242 'label' => esc_html__( 'Heading', 'copy-the-code' ),
243 ] );
244 $this->add_control( 'heading', [
245 'label' => esc_html__( 'Heading', 'copy-the-code' ),
246 'type' => Controls_Manager::TEXT,
247 'default' => esc_html__( 'Up to 50% off', 'copy-the-code' ),
248 ] );
249 $this->end_controls_section();
250 $this->start_controls_section( 'description_section', [
251 'label' => esc_html__( 'Short Description', 'copy-the-code' ),
252 ] );
253 $this->add_control( 'description', [
254 'label' => esc_html__( 'Short Description', 'copy-the-code' ),
255 'type' => Controls_Manager::WYSIWYG,
256 'default' => 'Get up to 50% off on all products. Offer valid till <b>31st December 2020</b>.',
257 ] );
258 $this->end_controls_section();
259 $this->start_controls_section( 'coupon_button_section', [
260 'label' => esc_html__( 'Coupon Code', 'copy-the-code' ),
261 ] );
262 $this->add_control( 'coupon_code', [
263 'label' => esc_html__( 'Coupon Code', 'copy-the-code' ),
264 'type' => Controls_Manager::TEXT,
265 'default' => esc_html__( 'CTC30', 'copy-the-code' ),
266 ] );
267 $this->add_control( 'display_slide_button', [
268 'label' => esc_html__( 'Display Slide Button', 'copy-the-code' ),
269 'type' => Controls_Manager::SWITCHER,
270 'default' => 'yes',
271 ] );
272 // Button Text.
273 $this->add_control( 'slide_button_text', [
274 'label' => esc_html__( 'Slide Button Text', 'copy-the-code' ),
275 'type' => Controls_Manager::TEXT,
276 'default' => esc_html__( 'Show Coupon Code', 'copy-the-code' ),
277 'condition' => [
278 'display_slide_button' => 'yes',
279 ],
280 ] );
281 // Button Link.
282 $this->add_control( 'button_link', [
283 'label' => esc_html__( 'Button Link', 'copy-the-code' ),
284 'type' => Controls_Manager::URL,
285 'default' => [
286 'url' => '#',
287 ],
288 'condition' => [
289 'display_slide_button' => 'yes',
290 ],
291 ] );
292 // Link target.
293 $this->add_control( 'link_target', [
294 'label' => esc_html__( 'Link Target', 'copy-the-code' ),
295 'type' => Controls_Manager::SELECT,
296 'default' => '_blank',
297 'options' => [
298 '_self' => esc_html__( 'Self', 'copy-the-code' ),
299 '_blank' => esc_html__( 'Blank', 'copy-the-code' ),
300 ],
301 'condition' => [
302 'display_slide_button' => 'yes',
303 ],
304 ] );
305 $this->end_controls_section();
306 $this->start_controls_section( 'details_section', [
307 'label' => esc_html__( 'Details', 'copy-the-code' ),
308 ] );
309 // Enable Toggle Details.
310 $this->add_control( 'toggle_details', [
311 'label' => esc_html__( 'Enable Toggle Details', 'copy-the-code' ),
312 'type' => Controls_Manager::SWITCHER,
313 'default' => 'yes',
314 ] );
315 // Details.
316 $this->add_control( 'details', [
317 'label' => esc_html__( 'Details', 'copy-the-code' ),
318 'type' => Controls_Manager::WYSIWYG,
319 'default' => '<ul><li>Get upto 50% off on all products.</li><li>
320 Offer valid till <b>31st December 2020</b>.</li><li>No coupon code required.</li></ul>',
321 ] );
322 $this->end_controls_section();
323 /**
324 * Group - Copy Button
325 */
326 $this->start_controls_section( 'button_section', [
327 'label' => esc_html__( 'Copy Button', 'copy-the-code' ),
328 ] );
329 $this->add_control( 'button_text', [
330 'label' => esc_html__( 'Copy Button Text', 'copy-the-code' ),
331 'type' => Controls_Manager::TEXT,
332 'default' => esc_html__( 'Copy Code', 'copy-the-code' ),
333 ] );
334 $this->add_control( 'button_text_copied', [
335 'label' => esc_html__( 'After Copy Button Text', 'copy-the-code' ),
336 'type' => Controls_Manager::TEXT,
337 'default' => esc_html__( 'Code Copied', 'copy-the-code' ),
338 ] );
339 // Show Icon.
340 $this->add_control( 'show_icon', [
341 'label' => esc_html__( 'Show Icon', 'copy-the-code' ),
342 'type' => Controls_Manager::SWITCHER,
343 'label_on' => esc_html__( 'Show', 'copy-the-code' ),
344 'label_off' => esc_html__( 'Hide', 'copy-the-code' ),
345 'return_value' => 'yes',
346 'default' => 'yes',
347 ] );
348 $this->add_control( 'icon_direction', [
349 'label' => esc_html__( 'Icon Direction', 'copy-the-code' ),
350 'type' => Controls_Manager::SELECT,
351 'default' => 'before',
352 'options' => [
353 'before' => esc_html__( 'Before', 'copy-the-code' ),
354 'after' => esc_html__( 'After', 'copy-the-code' ),
355 ],
356 'condition' => [
357 'show_icon' => 'yes',
358 ],
359 ] );
360 $this->add_responsive_control( 'icon_text_gap', [
361 'label' => esc_html__( 'Icon and Text Gap', 'copy-the-code' ),
362 'type' => Controls_Manager::SLIDER,
363 'size_units' => [ 'px', 'em' ],
364 'range' => [
365 'px' => [
366 'min' => 0,
367 'max' => 100,
368 ],
369 'em' => [
370 'min' => 0,
371 'max' => 10,
372 ],
373 ],
374 'selectors' => [
375 '{{WRAPPER}} .ctc-with-icon' => 'gap: {{SIZE}}{{UNIT}};',
376 ],
377 'condition' => [
378 'show_icon' => 'yes',
379 ],
380 ] );
381 $this->end_controls_section();
382 Helpers::register_pro_sections( $this, [
383 'Header',
384 'Heading',
385 'Description',
386 'Button',
387 'Coupon Code',
388 'Details',
389 'Details > Link',
390 'Details > Content'
391 ] );
392 }
393
394 }