PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.4
ShopBuilder – WooCommerce Builder For Elementor v2.1.4
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 2.3.0 All 62 releases
shopbuilder / app / Abstracts / Discount.php

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

217 lines 5.3 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 if ( $this->options['global_check'] ) {
60 return;
61 }
62
63 // Black Friday Notice.
64 if ( ! rtsb()->has_pro() && $start <= $current && $current <= $end ) {
65 if ( get_option( $this->options['option_name'] ) != '1' ) {
66 if ( ! isset( $GLOBALS['rtsb__notice'] ) ) {
67 $GLOBALS['rtsb__notice'] = 'rtsb__notice';
68 $this->offer_notice();
69 }
70 }
71 }
72 }
73
74 /**
75 * Black Friday Notice.
76 *
77 * @return void
78 */
79 private function offer_notice() {
80 add_action(
81 'admin_enqueue_scripts',
82 function () {
83 wp_enqueue_script( 'jquery' );
84 }
85 );
86
87 add_action(
88 'admin_notices',
89 function () {
90 ?>
91 <style>
92 .notice.rtsb-offer-notice {
93 --e-button-context-color: #5d3dfd;
94 --e-button-context-color-dark: #0047FF;
95 --e-button-context-tint: rgb(75 47 157/4%);
96 --e-focus-color: rgb(75 47 157/40%);
97 display:grid;
98 grid-template-columns: 100px auto;
99 padding-top: 15px;
100 padding-bottom: 12px;
101 column-gap: 15px;
102 }
103
104 .rtsb-offer-notice img {
105 grid-row: 1 / 4;
106 align-self: center;
107 justify-self: center;
108 }
109
110 .rtsb-offer-notice h3,
111 .rtsb-offer-notice p {
112 margin: 0 !important;
113 }
114
115 .rtsb-offer-notice .notice-text {
116 margin: 0 0 2px;
117 padding: 5px 0;
118 max-width: 100%;
119 font-size: 14px;
120 }
121
122 .rtsb-offer-notice .button-primary,
123 .rtsb-offer-notice .button-dismiss {
124 display: inline-block;
125 border: 0;
126 border-radius: 3px;
127 background: var(--e-button-context-color-dark);
128 color: #fff;
129 vertical-align: middle;
130 text-align: center;
131 text-decoration: none;
132 white-space: nowrap;
133 margin-right: 5px;
134 transition: all 0.3s;
135 }
136
137 .rtsb-offer-notice .button-primary:hover,
138 .rtsb-offer-notice .button-dismiss:hover {
139 background: var(--e-button-context-color);
140 color: #fff;
141 }
142
143 .rtsb-offer-notice .button-primary:focus,
144 .rtsb-offer-notice .button-dismiss:focus {
145 box-shadow: 0 0 0 1px #fff, 0 0 0 3px var(--e-button-context-color);
146 background: var(--e-button-context-color);
147 color: #fff;
148 }
149
150 .rtsb-offer-notice .button-dismiss {
151 border: 1px solid;
152 background: 0 0;
153 color: var(--e-button-context-color);
154 background: #fff;
155 }
156 </style>
157
158 <div class="rtsb-offer-notice notice notice-info is-dismissible"
159 data-rtsbdismissable="rtsb_offer">
160 <img alt="<?php echo esc_attr( $this->options['plugin_name'] ); ?>"
161 src="<?php echo esc_url( $this->options['image_url'] ); ?>"
162 width="100px"
163 height="100px"/>
164 <h3><?php echo sprintf( '%s – %s', esc_html( $this->options['plugin_name'] ), esc_html( $this->options['notice_for'] ) ); ?></h3>
165
166 <p class="notice-text">
167 <?php echo wp_kses_post( $this->options['notice_message'] ); ?>
168 </p>
169 <p>
170 <a class="button button-primary"
171 href="<?php echo esc_url( $this->options['download_link'] ); ?>" target="_blank">Buy Now</a>
172 <a class="button button-dismiss" href="#">Dismiss</a>
173 </p>
174 </div>
175
176 <?php
177 }
178 );
179
180 add_action(
181 'admin_footer',
182 function () {
183 ?>
184 <script type="text/javascript">
185 (function ($) {
186 $(function () {
187 setTimeout(function () {
188 $('div[data-rtsbdismissable] .notice-dismiss, div[data-rtsbdismissable] .button-dismiss')
189 .on('click', function (e) {
190 e.preventDefault();
191 $.post(ajaxurl, {
192 'action': 'rtsb_dismiss_offer_admin_notice',
193 'nonce': <?php echo wp_json_encode( wp_create_nonce( 'rtsb-offer-dismissible-notice' ) ); ?>
194 });
195 $(e.target).closest('.is-dismissible').remove();
196 });
197 }, 1000);
198 });
199 })(jQuery);
200 </script>
201 <?php
202 }
203 );
204
205 add_action(
206 'wp_ajax_rtsb_dismiss_offer_admin_notice',
207 function () {
208 check_ajax_referer( 'rtsb-offer-dismissible-notice', 'nonce' );
209 if ( ! empty( $this->options['option_name'] ) ) {
210 update_option( $this->options['option_name'], '1' );
211 }
212 wp_die();
213 }
214 );
215 }
216 }
217