PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 5.5.4
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v5.5.4
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 / includes / elementor / widgets / coupon / widget.php

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

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