PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / trunk
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution vtrunk
4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / widgets / qr-code / qr-code.php
shopengine / widgets / qr-code Last commit date
qr-code-config.php 11 months ago qr-code.php 9 months ago
qr-code.php
152 lines
1 <?php
2
3 namespace Elementor;
4
5 defined('ABSPATH') || exit;
6
7 class ShopEngine_Qr_Code extends \ShopEngine\Base\Widget
8 {
9
10 public function config()
11 {
12 return new ShopEngine_Qr_Code_Config();
13 }
14
15 protected function register_controls()
16 {
17
18 $this->start_controls_section(
19 'shopengine-qrcode-conent',
20 [
21 'label' => __('QR Code', 'shopengine'),
22 ]
23 );
24
25 $this->add_control(
26 'shopengine_size',
27 [
28 'label' => __('Size', 'shopengine'),
29 'type' => Controls_Manager::NUMBER,
30 'min' => 0,
31 'max' => 1000,
32 'step' => 1,
33 'default' => 150,
34 ]
35 );
36
37 $this->add_control(
38 'shopengine_add_cart_url',
39 [
40 'label' => __('Scan to Add to Cart URL', 'shopengine'),
41 'description' => __('If enabled, the QR code will generate a link that adds the product to the cart when scanned.', 'shopengine'),
42 'type' => Controls_Manager::SWITCHER,
43 'return_value' => 'yes',
44 'default' => 'no',
45 ]
46 );
47
48 $this->add_control(
49 'shopengine_direct_payment_url',
50 [
51 'label' => __('Scan to Direct Payment URL', 'shopengine'),
52 'description' => __('If enabled, the QR code will generate a link that adds the product to cart and redirects directly to checkout.', 'shopengine'),
53 'type' => Controls_Manager::SWITCHER,
54 'return_value' => 'yes',
55 'default' => 'no',
56 ]
57 );
58
59 $this->add_control(
60 'shopengine_quantity',
61 [
62 'label' => esc_html__('Quantity', 'shopengine'),
63 'type' => Controls_Manager::NUMBER,
64 'min' => 0,
65 'max' => 500,
66 'step' => 1,
67 'default' => 1,
68 'conditions' => [
69 'relation' => 'or',
70 'terms' => [
71 [
72 'name' => 'shopengine_add_cart_url',
73 'operator' => '===',
74 'value' => 'yes',
75 ],
76 [
77 'name' => 'shopengine_direct_payment_url',
78 'operator' => '===',
79 'value' => 'yes',
80 ],
81 ],
82 ],
83 ]
84 );
85
86 $this->add_responsive_control(
87 'shopengine_code_align',
88 [
89 'label' => esc_html__('Alignment', 'shopengine'),
90 'type' => Controls_Manager::CHOOSE,
91 'options' => [
92 'left' => [
93 'title' => esc_html__('Left', 'shopengine'),
94 'icon' => 'eicon-text-align-left',
95 ],
96 'center' => [
97 'title' => esc_html__('Center', 'shopengine'),
98 'icon' => 'eicon-text-align-center',
99 ],
100 'right' => [
101 'title' => esc_html__('Right', 'shopengine'),
102 'icon' => 'eicon-text-align-right',
103 ],
104 ],
105 'selectors' => [
106 '{{WRAPPER}} .shopengine-qrcode' => 'text-align: {{VALUE}};',
107 ],
108 'separator' => 'before',
109 ]
110 );
111
112 $this->end_controls_section();
113 }
114
115 protected function screen()
116 {
117
118 $post_type = get_post_type();
119 $product = \ShopEngine\Widgets\Products::instance()->get_product($post_type);
120 $settings = $this->get_settings_for_display();
121 $product_id = $product->get_id();
122 $quantity = ( !empty($settings['shopengine_quantity'] ) ? $settings['shopengine_quantity'] : 1 );
123
124 if ($settings['shopengine_add_cart_url'] == 'yes') {
125
126 $url = get_the_permalink( $product_id) . sprintf('?add-to-cart=%s&quantity=%s', $product_id, $quantity );
127
128 } elseif ($settings['shopengine_direct_payment_url'] == 'yes') {
129
130 $checkout_url = wc_get_checkout_url();
131 $url = $checkout_url . sprintf('?add-to-cart=%s&quantity=%s', $product_id, $quantity );
132
133 } else {
134
135 $url = get_the_permalink( $product_id );
136 }
137
138 $title = get_the_title( $product_id );
139 $product_url = urlencode($url);
140 $size = ( !empty($settings['shopengine_size']) ? $settings['shopengine_size'] : 150 );
141 $size = absint( $size );
142 $dimension = esc_attr($size . 'x' . $size);
143 $image_url = sprintf( 'https://api.qrserver.com/v1/create-qr-code/?size=%s&ecc=L&qzone=1&data=%s', $dimension, $product_url);
144
145 ?>
146 <div class="shopengine-qrcode">
147 <img src="<?php echo esc_url( $image_url ) ?>" alt="<?php echo esc_attr( $title ); ?>">
148 </div>
149 <?php
150 }
151 }
152