PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / trunk
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler vtrunk
1.7.0 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 All 50 releases
fluent-cart / app / Hooks / Handlers / ShortCodes / OrderReviewShortCode.php

OrderReviewShortCode.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler trunk, at app/Hooks/Handlers/ShortCodes/OrderReviewShortCode.php

54 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Hooks\Handlers\ShortCodes;
4
5 use FluentCart\App\App;
6 use FluentCart\App\Services\Renderer\OrderReviewRenderer;
7
8 /**
9 * [fluent_cart_order_review] — the "review your order" page as a shortcode, so
10 * a store can pick which page hosts it the same way it picks the receipt page.
11 *
12 * The ?fluent-cart=order-review route renders the same thing without a page.
13 * Both exist for the same reason the receipt has both: the route always works
14 * (nothing to configure, nothing for an owner to delete), and the page lets the
15 * owner put the store's own header, footer and styling around it.
16 */
17 class OrderReviewShortCode
18 {
19 public function register()
20 {
21 add_shortcode('fluent_cart_order_review', [$this, 'render']);
22 }
23
24 /**
25 * @param array|string $atts
26 * @return string
27 */
28 public function render($atts = [])
29 {
30 // The hash comes from the query string, not the shortcode: the page is
31 // one page serving every order, and the link in the email is what
32 // carries the identity.
33 $orderHash = sanitize_text_field((string) App::request()->get('order_hash', ''));
34
35 // In the block editor the shortcode is rendered for preview with no
36 // order in the URL, and a "we could not find that order" panel is a
37 // poor thing to show an admin laying out the page.
38 // The block editor previews it through the REST block renderer, with
39 // no action parameter at all, so that request is a preview as well.
40 $isEditorPreview = App::request()->get('action') === 'edit'
41 || (defined('REST_REQUEST') && REST_REQUEST);
42 if ($orderHash === '' && $isEditorPreview) {
43 return '';
44 }
45
46 ob_start();
47 // The page this shortcode sits on already prints its own title, so the
48 // renderer's <h1> would be the second identical heading on screen.
49 (new OrderReviewRenderer($orderHash, ['showTitle' => false]))->render();
50
51 return ob_get_clean();
52 }
53 }
54