| 1 |
<?php |
| 2 |
/** |
| 3 |
* Add to Cart Ajax Class. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Controllers\Frontend\Ajax; |
| 9 |
|
| 10 |
use RadiusTheme\SB\Helpers\Fns; |
| 11 |
use RadiusTheme\SB\Traits\SingletonTrait; |
| 12 |
|
| 13 |
// Do not allow directly accessing this file. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit( 'This script cannot be accessed directly.' ); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Add to Cart Ajax Class. |
| 20 |
*/ |
| 21 |
class UpdateCheckoutSection { |
| 22 |
/** |
| 23 |
* Singleton. |
| 24 |
*/ |
| 25 |
use SingletonTrait; |
| 26 |
|
| 27 |
/** |
| 28 |
* Class Constructor. |
| 29 |
* |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
private function __construct() { |
| 33 |
add_action( 'wp_ajax_rtsb_shopify_checkout_section_update', [ $this, 'response' ] ); |
| 34 |
add_action( 'wp_ajax_nopriv_rtsb_shopify_checkout_section_update', [ $this, 'response' ] ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Ajax Response. |
| 39 |
* |
| 40 |
* @return void |
| 41 |
*/ |
| 42 |
public function response() { |
| 43 |
WC()->cart->calculate_totals(); |
| 44 |
WC()->cart->calculate_shipping(); |
| 45 |
ob_start(); |
| 46 |
Fns::load_template( 'shopify-checkout/order-review-footer', [] ); |
| 47 |
$calculate = ob_get_clean(); |
| 48 |
ob_start(); |
| 49 |
Fns::load_template( 'shopify-checkout/shopify-shipping-method', [] ); |
| 50 |
$shipping_method = ob_get_clean(); |
| 51 |
wp_send_json_success( |
| 52 |
[ |
| 53 |
'order_calculate' => $calculate, |
| 54 |
'shipping_method' => $shipping_method, |
| 55 |
] |
| 56 |
); |
| 57 |
} |
| 58 |
} |
| 59 |
|