| 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 |
|