| 1 |
<?php |
| 2 |
/** |
| 3 |
* Beaver Builder Editor Compatibility. |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
/** |
| 13 |
* Checkout Markup |
| 14 |
* |
| 15 |
* @since 1.6.15 |
| 16 |
*/ |
| 17 |
class Cartflows_BB_Editor { |
| 18 |
|
| 19 |
/** |
| 20 |
* Member Variable |
| 21 |
* |
| 22 |
* @var object instance |
| 23 |
*/ |
| 24 |
private static $instance; |
| 25 |
|
| 26 |
/** |
| 27 |
* Initiator |
| 28 |
*/ |
| 29 |
public static function get_instance() { |
| 30 |
|
| 31 |
if ( ! isset( self::$instance ) ) { |
| 32 |
self::$instance = new self(); |
| 33 |
} |
| 34 |
|
| 35 |
return self::$instance; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Constructor |
| 40 |
*/ |
| 41 |
public function __construct() { |
| 42 |
if ( class_exists( 'FLBuilderModel' ) ) { |
| 43 |
$this->bb_editor_compatibility(); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Beaver Builder editor compatibility. |
| 49 |
*/ |
| 50 |
public function bb_editor_compatibility() { |
| 51 |
|
| 52 |
if ( FLBuilderModel::is_builder_active() ) { |
| 53 |
|
| 54 |
$current_post_id = get_the_id(); |
| 55 |
|
| 56 |
$cf_frontend = Cartflows_Frontend::get_instance(); |
| 57 |
|
| 58 |
/* Load woo templates from plugin. */ |
| 59 |
add_filter( 'woocommerce_locate_template', array( $cf_frontend, 'override_woo_template' ), 20, 3 ); |
| 60 |
|
| 61 |
do_action( 'cartflows_bb_editor_compatibility', $current_post_id ); |
| 62 |
|
| 63 |
/* Thank you filters. */ |
| 64 |
add_filter( 'cartflows_show_demo_order_details', '__return_true' ); |
| 65 |
|
| 66 |
add_action( 'cartflows_bb_before_checkout_shortcode', array( $this, 'before_checkout_shortcode_actions' ), 10, 2 ); |
| 67 |
|
| 68 |
add_action( |
| 69 |
'wp_head', |
| 70 |
function() { |
| 71 |
$current_post_id = get_the_id(); |
| 72 |
|
| 73 |
$cartflows_bb_vars = array( |
| 74 |
'wcf_enable_product_options' => get_post_meta( $current_post_id, 'wcf-enable-product-options', true ), |
| 75 |
'wcf_order_bump' => get_post_meta( $current_post_id, 'wcf-order-bump', true ), |
| 76 |
'wcf_pre_checkout_offer' => get_post_meta( $current_post_id, 'wcf-pre-checkout-offer', true ), |
| 77 |
); |
| 78 |
$localize_script = '<script type="text/javascript">'; |
| 79 |
$localize_script .= 'var CartFlowsBBVars = ' . wp_json_encode( $cartflows_bb_vars ) . ';'; |
| 80 |
$localize_script .= '</script>'; |
| 81 |
echo $localize_script; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 82 |
} |
| 83 |
); |
| 84 |
|
| 85 |
add_action( 'fl_builder_after_save_layout', array( $this, 'update_required_step_meta_data' ), 10, 4 ); |
| 86 |
|
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Before checkout shortcode actions. |
| 92 |
* |
| 93 |
* @param int $post_id step id. |
| 94 |
* @param bool $publish is published. |
| 95 |
* @param object $layout_data post data. |
| 96 |
* @param object $settings settings data. |
| 97 |
*/ |
| 98 |
public function update_required_step_meta_data( $post_id, $publish, $layout_data, $settings ) { |
| 99 |
|
| 100 |
if ( wcf()->utils->is_step_post_type( get_post_type( $post_id ) ) ) { |
| 101 |
|
| 102 |
$step_type = get_post_meta( $post_id, 'wcf-step-type', true ); |
| 103 |
$module_settings = false; |
| 104 |
|
| 105 |
switch ( $step_type ) { |
| 106 |
|
| 107 |
case 'checkout': |
| 108 |
foreach ( $layout_data as $node => $data ) { |
| 109 |
if ( ! empty( $data->type ) && 'module' === $data->type && ! empty( $data->settings->type ) && 'cartflows-bb-checkout-form' === $data->settings->type ) { |
| 110 |
$module_settings = $data->settings; |
| 111 |
break; |
| 112 |
} |
| 113 |
} |
| 114 |
$meta_keys = array( |
| 115 |
'checkout_layout' => 'wcf-checkout-layout', |
| 116 |
); |
| 117 |
break; |
| 118 |
|
| 119 |
case 'optin': |
| 120 |
break; |
| 121 |
|
| 122 |
default: |
| 123 |
} |
| 124 |
|
| 125 |
if ( $module_settings ) { |
| 126 |
|
| 127 |
foreach ( $meta_keys as $key => $meta_key ) { |
| 128 |
|
| 129 |
if ( isset( $module_settings->$key ) ) { |
| 130 |
update_post_meta( $post_id, $meta_key, $module_settings->$key ); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Before checkout shortcode actions. |
| 139 |
* |
| 140 |
* @param int $checkout_id checkout id. |
| 141 |
*/ |
| 142 |
public function before_checkout_shortcode_actions( $checkout_id ) { |
| 143 |
|
| 144 |
// Added to modify the fields labels and placeholders to display it in the preview mode. |
| 145 |
Cartflows_Checkout_Fields::get_instance()->checkout_field_actions(); |
| 146 |
|
| 147 |
do_action( 'cartflows_checkout_before_shortcode', $checkout_id ); |
| 148 |
} |
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Kicking this off by calling 'get_instance()' method |
| 154 |
*/ |
| 155 |
Cartflows_BB_Editor::get_instance(); |
| 156 |
|