PluginProbe
Ultimate Store Kit / 3.0.9
Ultimate Store Kit v3.0.9
3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 92 releases
ultimate-store-kit / modules / qr-code / widgets / qr-code.php

qr-code.php in Ultimate Store Kit 3.0.9, at modules/qr-code/widgets/qr-code.php

164 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimateStoreKit\Modules\QrCode\Widgets;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Group_Control_Border;
7 use Elementor\Group_Control_Box_Shadow;
8 use Elementor\Group_Control_Typography;
9 use Elementor\Group_Control_Background;
10 use UltimateStoreKit\Base\Module_Base;
11
12
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 // Exit if accessed directly
18
19 class QR_Code extends Module_Base {
20
21 public function get_name() {
22 return 'usk-qr-code';
23 }
24
25 public function get_title() {
26 return esc_html__('QR Code', 'ultimate-store-kit');
27 }
28
29 public function get_icon() {
30 return 'usk-widget-icon usk-icon-qr-code usk-new';
31 }
32
33 public function get_categories() {
34 return ['ultimate-store-kit'];
35 }
36
37 public function get_keywords() {
38 return ['product', 'qr', 'code', 'bar', 'scan', 'qr code'];
39 }
40
41 // public function get_script_depends() {
42 // return ['usk-checkout-coupon-form'];
43 // }
44
45 public function get_style_depends() {
46 if ($this->usk_is_edit_mode()) {
47 return ['usk-all-styles'];
48 } else {
49 return ['usk-font', 'usk-qr-code'];
50 }
51 }
52
53 // public function get_custom_help_url() {
54 // return 'https://youtu.be/3VkvuskVaNAM';
55 // }
56 public function has_widget_inner_wrapper(): bool {
57 return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
58 }
59 protected function is_dynamic_content(): bool {
60 return false;
61 }
62 protected function register_controls() {
63 $this->start_controls_section(
64 'section_content_qrcode',
65 [
66 'label' => __('QR Code', 'ultimate-store-kit'),
67 'tab' => Controls_Manager::TAB_CONTENT,
68 ]
69 );
70
71 $this->add_control(
72 'qr_code_dimesion_size',
73 [
74 'label' => __('Dimension Size', 'ultimate-store-kit'),
75 'type' => Controls_Manager::NUMBER,
76 'min' => 50,
77 'max' => 800,
78 'step' => 1,
79 'default' => 150,
80 ]
81 );
82
83 $this->add_control(
84 'qr_code_cart_url',
85 [
86 'label' => __('Enable Add to Cart URL', 'ultimate-store-kit'),
87 'type' => Controls_Manager::SWITCHER,
88 'return_value' => 'yes',
89 'default' => 'no',
90 'separator' => 'before',
91 ]
92 );
93 $this->add_control(
94 'qr_code_product_quantity',
95 [
96 'label' => __('Quantity', 'ultimate-store-kit'),
97 'type' => Controls_Manager::NUMBER,
98 'min' => 1,
99 'max' => 1000,
100 'step' => 1,
101 'default' => 1,
102 'dynamic' => ['active' => true],
103 'condition' => [
104 'qr_code_cart_url' => 'yes'
105 ]
106 ]
107 );
108
109 $this->add_control(
110 'qr_code_alignemnt',
111 [
112 'label' => __('Alignement', 'ultimate-store-kit'),
113 'type' => Controls_Manager::CHOOSE,
114 'options' => [
115 'left' => [
116 'title' => __('Left', 'ultimate-store-kit'),
117 'icon' => 'eicon-h-align-left',
118 ],
119 'center' => [
120 'title' => __('Center', 'ultimate-store-kit'),
121 'icon' => 'eicon-h-align-center',
122 ],
123 'right' => [
124 'title' => __('Right', 'ultimate-store-kit'),
125 'icon' => 'eicon-h-align-right',
126 ],
127 ],
128 'selectors' => [
129 '{{WRAPPER}} .usk-qrcode' => 'text-align: {{VALUE}};',
130 ],
131 'separator' => 'before',
132 ]
133 );
134
135 $this->end_controls_section();
136 }
137
138 protected function get_last_order_id() {
139 global $wpdb;
140 $results = $wpdb->get_col(
141 "
142 SELECT MAX(ID) FROM {$wpdb->prefix}posts
143 WHERE post_type LIKE 'product'
144 AND post_status = 'publish'"
145 );
146 return reset($results);
147 }
148
149 protected function render() {
150 $settings = $this->get_settings_for_display();
151 $product_id = ultimate_store_kit_is_preview() ? $this->get_last_order_id() : $product_id = get_the_ID();
152 $quantity = (!empty($settings['qr_code_product_quantity']) ? $settings['qr_code_product_quantity'] : 1);
153 if ('yes' === $settings['qr_code_cart_url']) {
154 $product_url = get_the_permalink($product_id) . sprintf('?add-to-cart=%s&quantity=%s', $product_id, $quantity);
155 } else {
156 $product_url = get_the_permalink($product_id);
157 }
158 $size = (!empty($settings['qr_code_dimesion_size']) ? $settings['qr_code_dimesion_size'] : 150);
159 $dimension = $size . 'x' . $size;
160 $image_src = sprintf('//api.qrserver.com/v1/create-qr-code/?size=%s&ecc=L&qzone=1&data=%s', $dimension, urlencode($product_url));
161 printf('<div class="usk-qrcode"><img src="%1$s" alt="%2$s"></div>', esc_url($image_src), esc_attr(get_the_title($product_id)));
162 }
163 }
164