PluginProbe
Ebook Store / 6.25
Ebook Store v6.25
6.25 6.24 6.23 6.22 6.21 6.20 trunk
ebook-store / settings-WooCommerce.php

settings-WooCommerce.php in Ebook Store 6.25, at settings-WooCommerce.php

413 lines 18.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ebook Store - "WooCommerce" settings tab.
4 *
5 * Rendered inside <div class="ebook-settings-panel"> by ebook_options.php, so this
6 * file emits <section> blocks only: no table rows.
7 *
8 * PHP 7.4 compatible.
9 *
10 * @package EbookStore
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 settings_fields( 'ebook-settings-group-woocommerce' );
18 do_settings_sections( 'ebook-settings-group-woocommerce' );
19
20 $woocommerce_enabled = (string) get_option( 'ebook_store_woocommerce_integration', $op->ebook_store_woocommerce_integration );
21 $hide_added_to_cart = (string) get_option( 'ebook_store_woocommerce_integration_no_added_to_cart', $op->ebook_store_woocommerce_integration_no_added_to_cart );
22 $required_order_status = (string) get_option( 'ebook_store_woocommerce_required_order_status', $op->ebook_store_woocommerce_required_order_status );
23 $pdf_reader_enabled = (string) get_option( 'ebook_store_woocommerce_pdf_reader', $op->ebook_store_woocommerce_pdf_reader );
24 $encrypt_pdf_enabled = (string) get_option( 'encrypt_pdf', 0 );
25
26 // A saved checkbox is either '1' or '' ; the class defaults are the integer 0.
27 $woocommerce_plugin_active = class_exists( 'WooCommerce' );
28 $integration_on = ( $woocommerce_enabled !== '' && $woocommerce_enabled !== '0' );
29 $pdf_reader_on = ( $pdf_reader_enabled !== '' && $pdf_reader_enabled !== '0' );
30 $encryption_on = ( $encrypt_pdf_enabled !== '' && $encrypt_pdf_enabled !== '0' );
31 $reader_conflict = ( $pdf_reader_on && $encryption_on );
32
33 $autocomplete_state = function_exists( 'ebook_store_get_autocomplete_woocommerce_setup_state' )
34 ? ebook_store_get_autocomplete_woocommerce_setup_state()
35 : array(
36 'installed' => false,
37 'active' => false,
38 'mode' => '',
39 'required_order_status' => sanitize_key( $required_order_status ),
40 'is_recommended' => false,
41 );
42
43 $autocomplete_setup_url = function_exists( 'ebook_store_get_autocomplete_woocommerce_setup_url' ) ? ebook_store_get_autocomplete_woocommerce_setup_url() : '';
44 $autocomplete_notice_status = isset( $_GET['ebook_wc_autocomplete_status'] ) ? sanitize_key( wp_unslash( $_GET['ebook_wc_autocomplete_status'] ) ) : '';
45 $autocomplete_notice_message = isset( $_GET['ebook_wc_autocomplete_message'] ) ? sanitize_text_field( wp_unslash( $_GET['ebook_wc_autocomplete_message'] ) ) : '';
46
47 $pdf_protection_url = ebook_store_get_settings_tab_url( 'PDF-Protection' );
48 $woocommerce_install_url = admin_url( 'plugin-install.php?tab=search&s=woocommerce' );
49
50 // The statuses a WooCommerce order can be in, described the way a bookseller
51 // thinks about them rather than the way WooCommerce names them internally.
52 $order_status_labels = array(
53 'pending' => __( 'Pending payment - the order exists but is not paid', 'ebook-store' ),
54 'on-hold' => __( 'On hold - waiting for a manual or offline payment', 'ebook-store' ),
55 'processing' => __( 'Processing - payment received, order not closed yet', 'ebook-store' ),
56 'completed' => __( 'Completed - payment received and the order is closed', 'ebook-store' ),
57 'cancelled' => __( 'Cancelled - the order was called off', 'ebook-store' ),
58 );
59
60 $selected_status_short = array(
61 'pending' => __( 'Pending payment', 'ebook-store' ),
62 'on-hold' => __( 'On hold', 'ebook-store' ),
63 'processing' => __( 'Processing', 'ebook-store' ),
64 'completed' => __( 'Completed', 'ebook-store' ),
65 'cancelled' => __( 'Cancelled', 'ebook-store' ),
66 );
67
68 $status_short_label = isset( $selected_status_short[ $required_order_status ] )
69 ? $selected_status_short[ $required_order_status ]
70 : $required_order_status;
71
72 $hero_aside = function () use ( $woocommerce_plugin_active, $integration_on, $pdf_reader_on, $reader_conflict, $status_short_label, $autocomplete_state, $woocommerce_install_url, $pdf_protection_url ) {
73 ?>
74 <aside class="ebook-settings-status-card">
75 <h4><?php echo esc_html__( 'Current status', 'ebook-store' ); ?></h4>
76 <ul class="ebook-settings-status-list">
77 <?php
78 ebook_store_status_row(
79 __( 'WooCommerce plugin', 'ebook-store' ),
80 $woocommerce_plugin_active ? 'ok' : 'error',
81 $woocommerce_plugin_active
82 ? __( 'Installed and active on this site.', 'ebook-store' )
83 : __( 'Not active. Every setting on this page is ignored until it is.', 'ebook-store' ),
84 $woocommerce_plugin_active
85 ? array()
86 : array(
87 'label' => __( 'Install WooCommerce', 'ebook-store' ),
88 'url' => $woocommerce_install_url,
89 )
90 );
91
92 if ( ! $integration_on ) {
93 ebook_store_status_row(
94 __( 'Selling through WooCommerce', 'ebook-store' ),
95 'muted',
96 __( 'Off. Ebooks are sold with the Ebook Store buy buttons instead.', 'ebook-store' )
97 );
98 } elseif ( ! $woocommerce_plugin_active ) {
99 ebook_store_status_row(
100 __( 'Selling through WooCommerce', 'ebook-store' ),
101 'warn',
102 __( 'Switched on here, but WooCommerce itself is missing.', 'ebook-store' )
103 );
104 } else {
105 ebook_store_status_row(
106 __( 'Selling through WooCommerce', 'ebook-store' ),
107 'ok',
108 __( 'On. Buyers check out in WooCommerce and Ebook Store delivers the file.', 'ebook-store' )
109 );
110 }
111
112 ebook_store_status_row(
113 __( 'Download released when the order is', 'ebook-store' ),
114 $integration_on ? 'ok' : 'muted',
115 $status_short_label
116 );
117
118 if ( $reader_conflict ) {
119 ebook_store_status_row(
120 __( 'Reading in the browser', 'ebook-store' ),
121 'error',
122 __( 'On, but PDF encryption is also on. The reader cannot open encrypted files.', 'ebook-store' ),
123 array(
124 'label' => __( 'Fix on PDF Protection', 'ebook-store' ),
125 'url' => $pdf_protection_url,
126 )
127 );
128 } else {
129 ebook_store_status_row(
130 __( 'Reading in the browser', 'ebook-store' ),
131 $pdf_reader_on ? 'ok' : 'muted',
132 $pdf_reader_on
133 ? __( 'On. Buyers can open their PDF from the WooCommerce order page.', 'ebook-store' )
134 : __( 'Off. Buyers download the file instead of reading it online.', 'ebook-store' )
135 );
136 }
137
138 if ( $integration_on && $woocommerce_plugin_active ) {
139 ebook_store_status_row(
140 __( 'Automatic order completion', 'ebook-store' ),
141 ! empty( $autocomplete_state['is_recommended'] ) ? 'ok' : 'warn',
142 ! empty( $autocomplete_state['is_recommended'] )
143 ? __( 'Paid ebook orders complete on their own, so buyers get the file immediately.', 'ebook-store' )
144 : __( 'Not set up. Paid orders may sit and wait for you before the file is released.', 'ebook-store' )
145 );
146 }
147 ?>
148 </ul>
149 </aside>
150 <?php
151 };
152
153 ebook_store_render_hero(
154 array(
155 'eyebrow' => __( 'WooCommerce', 'ebook-store' ),
156 'title' => __( 'Take the money in WooCommerce, deliver the ebook with Ebook Store.', 'ebook-store' ),
157 'intro' => __( 'Switch WooCommerce on, choose how far an order must get before the download is released, and decide whether buyers can read their PDF in the browser.', 'ebook-store' ),
158 'aside' => $hero_aside,
159 )
160 );
161
162 ebook_store_pro_banner( __( 'The WooCommerce integration', 'ebook-store' ) );
163
164 /* ---------------------------------------------------------------------------
165 * Anything that needs attention before the rest of the page is worth reading.
166 * ------------------------------------------------------------------------ */
167 if ( $autocomplete_notice_message !== '' || ! $woocommerce_plugin_active || $reader_conflict ) {
168
169 ebook_store_section_open(
170 array(
171 'eyebrow' => __( 'Check first', 'ebook-store' ),
172 'title' => __( 'Things to sort out', 'ebook-store' ),
173 'intro' => __( 'These points stop WooCommerce delivery from working the way you expect.', 'ebook-store' ),
174 'id' => 'ebook-woocommerce-prerequisites',
175 )
176 );
177
178 if ( $autocomplete_notice_message !== '' ) {
179 ebook_store_callout(
180 esc_html( $autocomplete_notice_message ),
181 $autocomplete_notice_status === 'success' ? 'success' : 'warning',
182 $autocomplete_notice_status === 'success' ? __( 'Done:', 'ebook-store' ) : __( 'Could not finish:', 'ebook-store' )
183 );
184 }
185
186 if ( ! $woocommerce_plugin_active ) {
187 ebook_store_callout(
188 sprintf(
189 /* translators: %s: link that opens the WordPress plugin installer, already wrapped in an anchor tag. */
190 __( 'The WooCommerce plugin is not active on this site, so nothing on this tab does anything yet: no WooCommerce checkout, no order-based delivery, no online reading from order pages. %s and come back to this page afterwards.', 'ebook-store' ),
191 '<a href="' . esc_url( $woocommerce_install_url ) . '">' . esc_html__( 'Install and activate WooCommerce', 'ebook-store' ) . '</a>'
192 ),
193 'warning',
194 __( 'WooCommerce is missing:', 'ebook-store' )
195 );
196 }
197
198 if ( $reader_conflict ) {
199 ebook_store_callout(
200 sprintf(
201 /* translators: %s: link to the PDF Protection settings tab, already wrapped in an anchor tag. */
202 __( 'Online PDF reading is switched on here, and PDF encryption is switched on as well. An encrypted PDF cannot be opened by the browser reader, so your buyers will see an error instead of their book. Either turn encryption off on the %s tab, or turn "Let buyers read the PDF in the browser" off below.', 'ebook-store' ),
203 '<a href="' . esc_url( $pdf_protection_url ) . '">' . esc_html__( 'PDF Protection', 'ebook-store' ) . '</a>'
204 ),
205 'warning',
206 __( 'These two settings clash:', 'ebook-store' )
207 );
208 }
209
210 ebook_store_section_close();
211 }
212
213 /* ---------------------------------------------------------------------------
214 * Turning the integration on.
215 * ------------------------------------------------------------------------ */
216 ebook_store_section_open(
217 array(
218 'eyebrow' => __( 'Commerce', 'ebook-store' ),
219 'title' => __( 'Sell your ebooks through WooCommerce', 'ebook-store' ),
220 'intro' => __( 'Buyers pay with your WooCommerce payment methods and appear in your WooCommerce orders, while Ebook Store keeps handling the file, the download link and the protection settings.', 'ebook-store' ),
221 'id' => 'ebook-woocommerce-integration',
222 'pro' => true,
223 )
224 );
225
226 ebook_store_toggle_grid_open();
227
228 ebook_store_toggle(
229 array(
230 'name' => 'ebook_store_woocommerce_integration',
231 'title' => __( 'Sell ebooks through WooCommerce', 'ebook-store' ),
232 'description' => __( 'Link each ebook to a WooCommerce product so buyers use the WooCommerce cart and checkout. Leave this off if you want to keep using the Ebook Store buy buttons on their own.', 'ebook-store' ),
233 'checked' => $woocommerce_enabled,
234 'pro' => true,
235 )
236 );
237
238 ebook_store_toggle_grid_close();
239
240 ebook_store_advanced_open();
241
242 ebook_store_toggle_grid_open();
243
244 ebook_store_toggle(
245 array(
246 'name' => 'ebook_store_woocommerce_integration_no_added_to_cart',
247 'title' => __( 'Hide the "Added to cart" message', 'ebook-store' ),
248 'description' => __( 'Stops WooCommerce showing its green confirmation bar every time a book is added to the cart. Purely cosmetic: nothing about the order changes.', 'ebook-store' ),
249 'checked' => $hide_added_to_cart,
250 'pro' => true,
251 )
252 );
253
254 ebook_store_toggle_grid_close();
255
256 ebook_store_advanced_close();
257
258 ebook_store_steps(
259 __( 'How a WooCommerce sale reaches the reader', 'ebook-store' ),
260 array(
261 esc_html__( 'A buyer adds your ebook to the WooCommerce cart and pays at the WooCommerce checkout.', 'ebook-store' ),
262 esc_html__( 'The order moves to the status you choose below.', 'ebook-store' ),
263 esc_html__( 'Ebook Store then emails the download link and shows it on the buyer\'s order page.', 'ebook-store' ),
264 '<a href="https://www.youtube.com/watch?v=kaEKQ0yTaWA" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Watch the WooCommerce setup video', 'ebook-store' ) . '</a>',
265 )
266 );
267
268 ebook_store_section_close();
269
270 /* ---------------------------------------------------------------------------
271 * When the download is released.
272 * ------------------------------------------------------------------------ */
273 ebook_store_section_open(
274 array(
275 'eyebrow' => __( 'Delivery', 'ebook-store' ),
276 'title' => __( 'When should the download be released?', 'ebook-store' ),
277 'intro' => __( 'WooCommerce moves every order through a series of statuses. Pick the point at which you are happy for the buyer to get the file.', 'ebook-store' ),
278 'id' => 'ebook-woocommerce-order-status',
279 'pro' => true,
280 )
281 );
282
283 ebook_store_grid_open( 2 );
284
285 ebook_store_field(
286 array(
287 'type' => 'select',
288 'name' => 'ebook_store_woocommerce_required_order_status',
289 'label' => __( 'Release the download when the order reaches', 'ebook-store' ),
290 'value' => $required_order_status,
291 'options' => $order_status_labels,
292 'pro' => true,
293 'help' => __( 'You can see these statuses in WooCommerce under Orders. <strong>Completed</strong> is the safest choice for ebooks: the money has arrived and the order is closed. <strong>Processing</strong> also means paid, but many shops still treat it as "not finished yet". Choosing <strong>Pending payment</strong> or <strong>On hold</strong> hands out the book before you have been paid, and <strong>Cancelled</strong> would only ever release it for orders you called off.', 'ebook-store' ),
294 )
295 );
296
297 ebook_store_steps(
298 __( 'Recommended setup for ebook shops', 'ebook-store' ),
299 array(
300 esc_html__( 'Mark every ebook product in WooCommerce as Virtual and Downloadable, so no shipping is asked for.', 'ebook-store' ),
301 esc_html__( 'Set the status above to Completed.', 'ebook-store' ),
302 esc_html__( 'Let paid ebook orders complete themselves, so nobody has to wait for you to click a button.', 'ebook-store' ),
303 )
304 );
305
306 ebook_store_grid_close();
307
308 /*
309 * The free "Autocomplete WooCommerce Orders" helper. Only worth showing once
310 * WooCommerce delivery is actually switched on.
311 */
312 if ( $integration_on && $woocommerce_plugin_active && ebook_store_has_pro_license() ) {
313
314 ebook_store_advanced_open( __( 'Automatic order completion', 'ebook-store' ) );
315
316 if ( ! empty( $autocomplete_state['is_recommended'] ) ) {
317
318 ebook_store_callout(
319 esc_html__( 'Autocomplete WooCommerce Orders is active, set to virtual and downloadable orders, and this page is set to release downloads on Completed orders. Buyers get their book straight after paying.', 'ebook-store' ),
320 'success',
321 __( 'Instant delivery is ready:', 'ebook-store' )
322 );
323
324 } else {
325
326 if ( empty( $autocomplete_state['installed'] ) ) {
327 $autocomplete_message = esc_html__( 'Paid ebook orders normally stop at "Processing" and wait for a shop owner to close them by hand, which delays every download. The free Autocomplete WooCommerce Orders plugin closes paid virtual and downloadable orders for you.', 'ebook-store' );
328 } elseif ( empty( $autocomplete_state['active'] ) ) {
329 $autocomplete_message = esc_html__( 'Autocomplete WooCommerce Orders is installed but switched off, so paid orders still wait for you before the download is released.', 'ebook-store' );
330 } elseif ( $autocomplete_state['mode'] !== 'virtual_downloadable' ) {
331 $autocomplete_message = esc_html__( 'Autocomplete WooCommerce Orders is running, but it is not yet set to the recommended "Virtual & Downloadable Orders" mode, so ebook orders are not being completed automatically.', 'ebook-store' );
332 } elseif ( $autocomplete_state['required_order_status'] !== 'completed' ) {
333 $autocomplete_message = esc_html__( 'Autocomplete WooCommerce Orders is completing paid ebook orders, but this page is not waiting for Completed orders, so the automation is not being used.', 'ebook-store' );
334 } else {
335 $autocomplete_message = esc_html__( 'Automatic order completion is not fully set up yet.', 'ebook-store' );
336 }
337
338 ebook_store_callout( $autocomplete_message, 'warning', __( 'Suggested improvement:', 'ebook-store' ) );
339
340 if ( $autocomplete_setup_url !== '' ) {
341 ?>
342 <p>
343 <a class="button" href="<?php echo esc_url( $autocomplete_setup_url ); ?>">
344 <?php echo esc_html__( 'Set up automatic order completion', 'ebook-store' ); ?>
345 </a>
346 </p>
347 <p class="description">
348 <?php echo esc_html__( 'This installs and activates the free Autocomplete WooCommerce Orders plugin, sets it to virtual and downloadable orders, and switches the status above to Completed. You can undo any of it afterwards.', 'ebook-store' ); ?>
349 </p>
350 <?php
351 }
352 }
353
354 ebook_store_advanced_close();
355 }
356
357 ebook_store_section_close();
358
359 /* ---------------------------------------------------------------------------
360 * Reading in the browser.
361 * ------------------------------------------------------------------------ */
362 ebook_store_section_open(
363 array(
364 'eyebrow' => __( 'Reading experience', 'ebook-store' ),
365 'title' => __( 'Reading the book in the browser', 'ebook-store' ),
366 'intro' => __( 'Buyers can open their PDF straight from their WooCommerce order page instead of downloading it first.', 'ebook-store' ),
367 'id' => 'ebook-woocommerce-reader',
368 'pro' => true,
369 )
370 );
371
372 ebook_store_advanced_open();
373
374 ebook_store_toggle_grid_open();
375
376 ebook_store_toggle(
377 array(
378 'name' => 'ebook_store_woocommerce_pdf_reader',
379 'title' => __( 'Let buyers read the PDF in the browser', 'ebook-store' ),
380 'description' => __( 'Adds a "Read online" link next to the download on the WooCommerce order page. This only works with unencrypted PDFs.', 'ebook-store' ),
381 'checked' => $pdf_reader_enabled,
382 'pro' => true,
383 )
384 );
385
386 ebook_store_toggle_grid_close();
387
388 if ( $reader_conflict ) {
389 ebook_store_callout(
390 sprintf(
391 /* translators: %s: link to the PDF Protection settings tab, already wrapped in an anchor tag. */
392 __( 'PDF encryption is currently on, so the browser reader cannot open your files. Turn encryption off on the %s tab if you want online reading, or leave encryption on and switch online reading off here. Keeping both on gives buyers a broken page.', 'ebook-store' ),
393 '<a href="' . esc_url( $pdf_protection_url ) . '">' . esc_html__( 'PDF Protection', 'ebook-store' ) . '</a>'
394 ),
395 'warning',
396 __( 'Will not work as set:', 'ebook-store' )
397 );
398 } else {
399 ebook_store_callout(
400 sprintf(
401 /* translators: %s: link to the PDF Protection settings tab, already wrapped in an anchor tag. */
402 __( 'Before you switch this on, check that PDF encryption is off on the %s tab. Encrypted files cannot be shown by the browser reader.', 'ebook-store' ),
403 '<a href="' . esc_url( $pdf_protection_url ) . '">' . esc_html__( 'PDF Protection', 'ebook-store' ) . '</a>'
404 ),
405 'soft',
406 __( 'Good to know:', 'ebook-store' )
407 );
408 }
409
410 ebook_store_advanced_close();
411
412 ebook_store_section_close();
413