PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.5.0
ShopBuilder – WooCommerce Builder For Elementor v2.5.0
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 2.5.0, at app/Abstracts/Discount.php

215 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 $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 </style>
154
155 <div class="rtsb-offer-notice notice notice-info is-dismissible"
156 data-rtsbdismissable="rtsb_offer">
157 <img alt="<?php echo esc_attr( $this->options['plugin_name'] ); ?>"
158 src="<?php echo esc_url( $this->options['image_url'] ); ?>"
159 width="100px"
160 height="100px"/>
161 <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>
162
163 <p class="notice-text">
164 <?php echo wp_kses_post( $this->options['notice_message'] ); ?>
165 </p>
166 <p style="display: flex; align-items: center;">
167 <a class="button button-primary"
168 href="<?php echo esc_url( $this->options['download_link'] ); ?>" target="_blank">Buy Now</a>
169 <a class="button button-dismiss" href="#">Dismiss</a>
170 </p>
171 </div>
172
173 <?php
174 },
175 9
176 );
177
178 add_action(
179 'admin_footer',
180 function () {
181 ?>
182 <script type="text/javascript">
183 (function ($) {
184 $(function () {
185 setTimeout(function () {
186 $('div[data-rtsbdismissable] .notice-dismiss, div[data-rtsbdismissable] .button-dismiss')
187 .on('click', function (e) {
188 e.preventDefault();
189 $.post(ajaxurl, {
190 'action': 'rtsb_dismiss_offer_admin_notice',
191 'nonce': <?php echo wp_json_encode( wp_create_nonce( 'rtsb-offer-dismissible-notice' ) ); ?>
192 });
193 $(e.target).closest('.is-dismissible').remove();
194 });
195 }, 1000);
196 });
197 })(jQuery);
198 </script>
199 <?php
200 }
201 );
202
203 add_action(
204 'wp_ajax_rtsb_dismiss_offer_admin_notice',
205 function () {
206 check_ajax_referer( 'rtsb-offer-dismissible-notice', 'nonce' );
207 if ( ! empty( $this->options['option_name'] ) ) {
208 update_option( $this->options['option_name'], '1' );
209 }
210 wp_die();
211 }
212 );
213 }
214 }
215