PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.3
ShopBuilder – WooCommerce Builder For Elementor v3.2.3
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Abstracts / Discount.php

Discount.php in ShopBuilder – WooCommerce Builder For Elementor 3.2.3, at app/Abstracts/Discount.php

225 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Special Offer.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Abstracts;
9
10 // Do not allow directly accessing this file.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 'This script cannot be accessed directly.' );
13 }
14
15 /**
16 * Black Friday Offer.
17 */
18 abstract class Discount {
19 /**
20 * @var array
21 */
22 protected $options = [];
23
24 /**
25 * Class Constructor.
26 *
27 * @return void
28 */
29 public function __construct() {
30 add_action( 'admin_init', [ $this, 'show_notice' ] );
31 }
32
33 /**
34 * @return array
35 */
36 abstract public function the_options(): array;
37
38 /**
39 * @return void
40 */
41 public function show_notice() {
42 $defaults = [
43 'download_link' => rtsb()->pro_version_link(),
44 'global_check' => false,
45 'plugin_name' => 'ShopBuilder Pro',
46 'image_url' => rtsb()->get_assets_uri( 'images/shopbuilder-100x100.svg' ),
47 'option_name' => '',
48 'start_date' => '',
49 'end_date' => '',
50 'notice_for' => 'Cyber Monday Deal!!',
51 'notice_message' => '',
52 ];
53 $options = apply_filters( 'rtsb_offer_notice', $this->the_options() );
54 $this->options = wp_parse_args( $options, $defaults );
55 $current = time();
56 $start = strtotime( $this->options['start_date'] );
57 $end = strtotime( $this->options['end_date'] );
58
59 $global = $this->options['global_check'] ?? 'rtsb__notice';
60 // Black Friday Notice.
61 if ( $start <= $current && $current <= $end ) {
62 if ( get_option( $this->options['option_name'] ) != '1' ) {
63 if ( ! isset( $GLOBALS[ $global ] ) ) {
64 $GLOBALS[ $global ] = $global;
65 $this->offer_notice();
66 }
67 }
68 }
69 }
70
71 /**
72 * Black Friday Notice.
73 *
74 * @return void
75 */
76 private function offer_notice() {
77 add_action(
78 'admin_enqueue_scripts',
79 function () {
80 wp_enqueue_script( 'jquery' );
81 }
82 );
83
84 add_action(
85 'admin_notices',
86 function () {
87 ?>
88 <style>
89 .notice.rtsb-offer-notice {
90 --e-button-context-color: #5d3dfd;
91 --e-button-context-color-dark: #0047FF;
92 --e-button-context-tint: rgb(75 47 157/4%);
93 --e-focus-color: rgb(75 47 157/40%);
94 display:grid;
95 grid-template-columns: 100px auto;
96 padding-top: 15px;
97 padding-bottom: 12px;
98 column-gap: 15px;
99 }
100
101 .rtsb-offer-notice img {
102 grid-row: 1 / 4;
103 align-self: center;
104 justify-self: center;
105 }
106
107 .rtsb-offer-notice h3,
108 .rtsb-offer-notice p {
109 margin: 0 !important;
110 }
111
112 .rtsb-offer-notice .notice-text {
113 margin: 0 0 2px;
114 padding: 5px 0;
115 max-width: 100%;
116 font-size: 14px;
117 }
118
119 .rtsb-offer-notice .button-primary,
120 .rtsb-offer-notice .button-dismiss {
121 display: inline-block;
122 border: 0;
123 border-radius: 3px;
124 background: var(--e-button-context-color-dark);
125 color: #fff;
126 vertical-align: middle;
127 text-align: center;
128 text-decoration: none;
129 white-space: nowrap;
130 margin-right: 5px;
131 transition: all 0.3s;
132 }
133
134 .rtsb-offer-notice .button-primary:hover,
135 .rtsb-offer-notice .button-dismiss:hover {
136 background: var(--e-button-context-color);
137 color: #fff;
138 }
139
140 .rtsb-offer-notice .button-primary:focus,
141 .rtsb-offer-notice .button-dismiss:focus {
142 box-shadow: 0 0 0 1px #fff, 0 0 0 3px var(--e-button-context-color);
143 background: var(--e-button-context-color);
144 color: #fff;
145 }
146
147 .rtsb-offer-notice .button-dismiss {
148 border: 1px solid;
149 background: 0 0;
150 color: var(--e-button-context-color);
151 background: #fff;
152 }
153
154 .rtsb-offer-notice .offer-footer {
155 padding-top: 10px;
156 }
157
158 .rtsb-offer-notice .notice-text b {
159 display: inline-block;
160 transform: skewX(-10deg);
161 line-height: 1;
162 }
163 </style>
164
165 <div class="rtsb-offer-notice notice notice-info is-dismissible"
166 data-rtsbdismissable="rtsb_offer">
167 <img alt="<?php echo esc_attr( $this->options['plugin_name'] ); ?>"
168 src="<?php echo esc_url( $this->options['image_url'] ); ?>"
169 width="100px"
170 height="100px"/>
171 <h3 style="display: flex; align-items: center;"><?php echo sprintf( '%s – %s', esc_html( $this->options['plugin_name'] ), wp_kses_post( $this->options['notice_for'] ) ); ?></h3>
172
173 <p class="notice-text">
174 <?php echo wp_kses_post( $this->options['notice_message'] ); ?>
175 </p>
176 <p class="offer-footer" style="display: flex; align-items: center;">
177 <a class="button button-primary"
178 href="<?php echo esc_url( $this->options['download_link'] ); ?>" target="_blank">Buy Now</a>
179 <a class="button button-dismiss" href="#">Dismiss</a>
180 </p>
181 </div>
182
183 <?php
184 },
185 9
186 );
187
188 add_action(
189 'admin_footer',
190 function () {
191 ?>
192 <script type="text/javascript">
193 (function ($) {
194 $(function () {
195 setTimeout(function () {
196 $('div[data-rtsbdismissable] .notice-dismiss, div[data-rtsbdismissable] .button-dismiss')
197 .on('click', function (e) {
198 e.preventDefault();
199 $.post(ajaxurl, {
200 'action': 'rtsb_dismiss_offer_admin_notice',
201 'nonce': <?php echo wp_json_encode( wp_create_nonce( 'rtsb-offer-dismissible-notice' ) ); ?>
202 });
203 $(e.target).closest('.is-dismissible').remove();
204 });
205 }, 1000);
206 });
207 })(jQuery);
208 </script>
209 <?php
210 }
211 );
212
213 add_action(
214 'wp_ajax_rtsb_dismiss_offer_admin_notice',
215 function () {
216 check_ajax_referer( 'rtsb-offer-dismissible-notice', 'nonce' );
217 if ( ! empty( $this->options['option_name'] ) ) {
218 update_option( $this->options['option_name'], '1' );
219 }
220 wp_die();
221 }
222 );
223 }
224 }
225