| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Shortcode; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
use StoreEngine\Classes\Order; |
| 10 |
use StoreEngine\Utils\Formatting; |
| 11 |
use StoreEngine\Utils\Helper; |
| 12 |
use StoreEngine\Utils\Template; |
| 13 |
use WP_Error; |
| 14 |
|
| 15 |
class OrderBillingAddress { |
| 16 |
|
| 17 |
public function __construct() { |
| 18 |
add_shortcode( 'storeengine_order_billing_address', [ $this, 'render' ] ); |
| 19 |
} |
| 20 |
|
| 21 |
public function render( $atts ) { |
| 22 |
$attributes = shortcode_atts( [ |
| 23 |
'dummy' => false, |
| 24 |
], $atts ); |
| 25 |
$dummy_order = Formatting::string_to_bool( $attributes['dummy'] ); |
| 26 |
|
| 27 |
if ( ! $dummy_order ) { |
| 28 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 29 |
$order_hash = isset( $_GET['order_hash'] ) ? sanitize_text_field( wp_unslash( $_GET['order_hash'] ) ) : ''; |
| 30 |
$order = Helper::get_order_by_key( $order_hash ); |
| 31 |
$order = $order instanceof WP_Error ? false : $order; |
| 32 |
|
| 33 |
// Fall back to sample content when there's no real order to show |
| 34 |
// (page opened directly, previewed, or rendered in the editor). |
| 35 |
if ( ! $order ) { |
| 36 |
$dummy_order = true; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
if ( $dummy_order ) { |
| 41 |
$order = new Order(); |
| 42 |
$order->set_billing_first_name( 'John' ); |
| 43 |
$order->set_billing_last_name( 'Doe' ); |
| 44 |
$order->set_billing_address_1( 'Chuadanga Bus Stand, Abdur Razzak Complex' ); |
| 45 |
$order->set_billing_address_2( '4th Floor' ); |
| 46 |
$order->set_billing_city( 'Khulna' ); |
| 47 |
$order->set_billing_state( 'Jhenaidah' ); |
| 48 |
$order->set_billing_country( 'BD' ); |
| 49 |
$order->set_billing_email( 'support@storeengine.pro' ); |
| 50 |
$order->set_billing_phone( '01234567890123' ); |
| 51 |
$order->set_billing_company( 'KodeZen' ); |
| 52 |
$order->set_billing_postcode( '12345' ); |
| 53 |
} |
| 54 |
|
| 55 |
ob_start(); |
| 56 |
Template::get_template( 'shortcode/order-billing-address.php', [ |
| 57 |
'order' => $order, |
| 58 |
] ); |
| 59 |
|
| 60 |
return ob_get_clean(); |
| 61 |
} |
| 62 |
} |
| 63 |
|