| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Shortcode; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
use StoreEngine\Utils\Formatting; |
| 10 |
use StoreEngine\Utils\Helper; |
| 11 |
use StoreEngine\Utils\Template; |
| 12 |
|
| 13 |
class CheckoutForm { |
| 14 |
public function __construct() { |
| 15 |
add_shortcode( 'storeengine_checkout_form', array( $this, 'render_checkout_form' ) ); |
| 16 |
} |
| 17 |
|
| 18 |
public function render_checkout_form(): string { |
| 19 |
$cart = Helper::cart(); |
| 20 |
do_action( 'storeengine/cart/check_items' ); |
| 21 |
$is_cart_empty = $cart->is_cart_empty(); |
| 22 |
$cart_sub_total = $cart->get_cart_subtotal(); |
| 23 |
$products = $cart->get_cart_items(); |
| 24 |
|
| 25 |
if ( Formatting::string_to_bool( get_query_var( 'order_pay' ) ) ) { |
| 26 |
$order = Helper::get_order( absint( get_query_var( 'order_id' ) ) ); |
| 27 |
if ( is_wp_error( $order ) ) { |
| 28 |
return ''; |
| 29 |
} |
| 30 |
} else { |
| 31 |
$order = Helper::get_recent_draft_order(); |
| 32 |
} |
| 33 |
|
| 34 |
$current_user_email = ( is_user_logged_in() ) ? wp_get_current_user()->user_email : ''; |
| 35 |
ob_start(); |
| 36 |
|
| 37 |
Template::get_template( 'shortcode/checkout-form.php', [ |
| 38 |
'is_cart_empty' => $is_cart_empty, |
| 39 |
'cart_sub_total' => $cart_sub_total, |
| 40 |
'products' => $products, |
| 41 |
'product_query' => null, |
| 42 |
'order' => $order, |
| 43 |
'current_user_email' => $current_user_email, |
| 44 |
'is_digital_cart' => $cart->needs_shipping(), |
| 45 |
] ); |
| 46 |
|
| 47 |
return ob_get_clean(); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
} |
| 52 |
|