PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 2.0.5
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v2.0.5
3.1.4 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 All 93 releases
ultimate-store-kit / modules / qr-code / widgets / qr-code.php

qr-code.php in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 2.0.5, at modules/qr-code/widgets/qr-code.php

158 lines 5.1 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 protected function register_controls() {
57 $this->start_controls_section(
58 'section_content_qrcode',
59 [
60 'label' => __('QR Code', 'ultimate-store-kit'),
61 'tab' => Controls_Manager::TAB_CONTENT,
62 ]
63 );
64
65 $this->add_control(
66 'qr_code_dimesion_size',
67 [
68 'label' => __('Dimension Size', 'ultimate-store-kit'),
69 'type' => Controls_Manager::NUMBER,
70 'min' => 50,
71 'max' => 800,
72 'step' => 1,
73 'default' => 150,
74 ]
75 );
76
77 $this->add_control(
78 'qr_code_cart_url',
79 [
80 'label' => __('Enable Add to Cart URL', 'ultimate-store-kit'),
81 'type' => Controls_Manager::SWITCHER,
82 'return_value' => 'yes',
83 'default' => 'no',
84 'separator' => 'before',
85 ]
86 );
87 $this->add_control(
88 'qr_code_product_quantity',
89 [
90 'label' => __('Quantity', 'ultimate-store-kit'),
91 'type' => Controls_Manager::NUMBER,
92 'min' => 1,
93 'max' => 1000,
94 'step' => 1,
95 'default' => 1,
96 'dynamic' => ['active' => true],
97 'condition' => [
98 'qr_code_cart_url' => 'yes'
99 ]
100 ]
101 );
102
103 $this->add_control(
104 'qr_code_alignemnt',
105 [
106 'label' => __('Alignement', 'ultiamte-store-kit'),
107 'type' => Controls_Manager::CHOOSE,
108 'options' => [
109 'left' => [
110 'title' => __('Left', 'ultiamte-store-kit'),
111 'icon' => 'eicon-h-align-left',
112 ],
113 'center' => [
114 'title' => __('Center', 'ultiamte-store-kit'),
115 'icon' => 'eicon-h-align-center',
116 ],
117 'right' => [
118 'title' => __('Right', 'ultiamte-store-kit'),
119 'icon' => 'eicon-h-align-right',
120 ],
121 ],
122 'selectors' => [
123 '{{WRAPPER}} .usk-qrcode' => 'text-align: {{VALUE}};',
124 ],
125 'separator' => 'before',
126 ]
127 );
128
129 $this->end_controls_section();
130 }
131
132 protected function get_last_order_id() {
133 global $wpdb;
134 $results = $wpdb->get_col(
135 "
136 SELECT MAX(ID) FROM {$wpdb->prefix}posts
137 WHERE post_type LIKE 'product'
138 AND post_status = 'publish'"
139 );
140 return reset($results);
141 }
142
143 protected function render() {
144 $settings = $this->get_settings_for_display();
145 $product_id = ultimate_store_kit_is_preview() ? $this->get_last_order_id() : $product_id = get_the_ID();
146 $quantity = (!empty($settings['qr_code_product_quantity']) ? $settings['qr_code_product_quantity'] : 1);
147 if ('yes' === $settings['qr_code_cart_url']) {
148 $product_url = get_the_permalink($product_id) . sprintf('?add-to-cart=%s&quantity=%s', $product_id, $quantity);
149 } else {
150 $product_url = get_the_permalink($product_id);
151 }
152 $size = (!empty($settings['qr_code_dimesion_size']) ? $settings['qr_code_dimesion_size'] : 150);
153 $dimension = $size . 'x' . $size;
154 $image_src = sprintf('//api.qrserver.com/v1/create-qr-code/?size=%s&ecc=L&qzone=1&data=%s', $dimension, urlencode($product_url));
155 printf('<div class="usk-qrcode"><img src="%1$s" alt="%2$s"></div>', esc_url($image_src), esc_html(get_the_title($product_id)));
156 }
157 }
158