| 1 |
<?php |
| 2 |
|
| 3 |
namespace RadiusTheme\SB\Modules\CheckoutEditor; |
| 4 |
|
| 5 |
// Do not allow directly accessing this file. |
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit( 'This script cannot be accessed directly.' ); |
| 8 |
} |
| 9 |
|
| 10 |
|
| 11 |
use RadiusTheme\SB\Helpers\Fns; |
| 12 |
use RadiusTheme\SB\Models\GeneralList; |
| 13 |
use RadiusTheme\SB\Traits\SingletonTrait; |
| 14 |
|
| 15 |
/** |
| 16 |
* CheckoutEditorInit |
| 17 |
*/ |
| 18 |
final class CheckoutEditorInit { |
| 19 |
/** |
| 20 |
* Singleton Trait. |
| 21 |
*/ |
| 22 |
use SingletonTrait; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var array |
| 26 |
*/ |
| 27 |
private static $cache = []; |
| 28 |
|
| 29 |
/** |
| 30 |
* @var array|mixed |
| 31 |
*/ |
| 32 |
private array $options; |
| 33 |
|
| 34 |
/** |
| 35 |
* Notifications hooks. |
| 36 |
*/ |
| 37 |
private function __construct() { |
| 38 |
// If the cached result doesn't exist, fetch it from the database. |
| 39 |
global $checkout_editor_settings; // Define global variable. |
| 40 |
$this->options = Fns::get_options( 'modules', 'checkout_fields_editor' ); // Assign options to the global variable. |
| 41 |
$checkout_editor_settings = $this->options; |
| 42 |
$this->disable_general_settings(); |
| 43 |
GeneralCheckout::instance(); |
| 44 |
if ( 'on' === ( $this->options['modify_billing_form'] ?? '' ) ) { |
| 45 |
BillingFields::instance(); |
| 46 |
} |
| 47 |
if ( 'on' === ( $this->options['modify_shipping_form'] ?? '' ) ) { |
| 48 |
ShippingFields::instance(); |
| 49 |
} |
| 50 |
if ( 'on' === ( $this->options['modify_additional_form'] ?? '' ) ) { |
| 51 |
AdditionalFields::instance(); |
| 52 |
} |
| 53 |
do_action( 'rtsb/checkout/editor/init' ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* @return void |
| 58 |
*/ |
| 59 |
public function disable_general_settings() { |
| 60 |
$elementor_list = GeneralList::instance()->get_data(); |
| 61 |
$billing_settings = $elementor_list['billing_form'] ?? []; |
| 62 |
$shipping_form = $elementor_list['shipping_form'] ?? []; |
| 63 |
if ( ! empty( $billing_settings['active'] ) ) { |
| 64 |
Fns::set_options( 'general', 'billing_form', [ 'active' => '' ] ); |
| 65 |
} |
| 66 |
if ( ! empty( $shipping_form['active'] ) ) { |
| 67 |
Fns::set_options( 'general', 'shipping_form', [ 'active' => '' ] ); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|