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

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