PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / widgets / block / classes / class-wpfnl-gutenberg-editor.php

class-wpfnl-gutenberg-editor.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at includes/core/widgets/block/classes/class-wpfnl-gutenberg-editor.php

137 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gutenberg block
4 *
5 * @package WPFunnels\Widgets\Gutenberg
6 */
7 namespace WPFunnels\Widgets\Gutenberg;
8
9 use WPFunnels\Meta\Wpfnl_Default_Meta;
10 use WPFunnels\Traits\SingletonTrait;
11 use WPFunnels\Wpfnl;
12 use WPFunnels\Wpfnl_functions;
13
14 class Wpfnl_Gutenberg_Editor {
15
16 use SingletonTrait;
17
18 public function __construct() {
19 $this->gb_compatibility();
20 }
21
22
23 private function gb_compatibility() {
24 add_action( 'admin_init', array( $this, 'editor_compatibility' ) );
25 add_action( 'wpfunnels/before_gb_checkout_form_ajax', array( $this, 'load_gb_cf_ajax_action' ), 10, 2 );
26 }
27
28
29 /**
30 * Editor compatibility action for gutenberg
31 *
32 * @since 2.0.3
33 */
34 public function editor_compatibility() {
35
36 if( Wpfnl_functions::is_step_edit_page() && Wpfnl_functions::is_wc_active() ) {
37 if(is_admin()) {
38 add_filter( 'wpfunnels/show_dummy_order_details', '__return_true' );
39 }
40 $this->before_checkout_actions();
41 $frontend = Wpfnl::get_instance()->frontend;
42 add_filter('woocommerce_locate_template', array( $frontend, 'wpfunnels_woocommerce_locate_template' ), 20, 3);
43
44 $step_id = isset($_POST['post_id']) ? intval( $_POST['post_id'] ) : 0;
45
46 $show_coupon = Wpfnl::get_instance()->meta->get_checkout_meta_value( $step_id, '_wpfnl_checkout_coupon' );
47 if( 'no' === $show_coupon ) {
48 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
49 }
50 }
51 }
52
53 /**
54 * Before checkout shortcode actions
55 *
56 * @since 2.0.3
57 */
58 private function before_checkout_actions() {
59 wc()->frontend_includes();
60 /* For preview */
61 add_filter('woocommerce_checkout_redirect_empty_cart', '__return_false');
62 }
63
64
65 /**
66 * This will be only triggered on checkout form block. and only in the
67 * editor page on ajax call
68 *
69 * @param $checkout_id
70 * @param $post_data
71 */
72 public function load_gb_cf_ajax_action( $checkout_id, $post_data ) {
73 $frontend = Wpfnl::get_instance()->frontend;
74 add_filter('woocommerce_locate_template', array( $frontend, 'wpfunnels_woocommerce_locate_template' ), 20, 3);
75
76 $default_settings = Wpfnl_Default_Meta::get_default_order_bump_meta();
77 $ob_data = isset( $post_data['order_bump_data'] ) ? $post_data['order_bump_data'] : $default_settings;
78 $ob_settings = $this->get_order_bump_settings_for_preview( $checkout_id, $ob_data );
79
80 update_post_meta($checkout_id, 'order-bump-settings', $ob_settings);
81 do_action('wpfunnels/gb_render_order_bump_ajax', $checkout_id, $ob_settings );
82 }
83
84
85 /**
86 * Get order bump settings for preview
87 *
88 * @param $post_id
89 * @param $post_data
90 *
91 * @return mixed
92 *
93 * @since 2.0.4
94 */
95 private function get_order_bump_settings_for_preview( $post_id, $post_data ) {
96 // $order_bump_settings = get_post_meta( $post_id, 'order-bump-settings', true );
97 $order_bump_settings = Wpfnl_functions::get_ob_settings( $post_id );
98 if( $order_bump_settings ) {
99 return $this->replace_ob_settings_with_block_data( $order_bump_settings, $post_data );
100 }
101 return [];
102 }
103
104
105 /**
106 * Replace ob settings with widget data
107 *
108 * @param $order_bump_settings
109 * @param $post_data
110 *
111 * @return mixed
112 *
113 * @since 2.0.4
114 */
115 private function replace_ob_settings_with_block_data( $order_bump_settings, $post_data ) {
116 if( empty($post_data) ) {
117 return $order_bump_settings;
118 }
119
120 if( is_array( $post_data ) ){
121 foreach( $post_data as $key => $data ){
122 $order_bump_settings[$key]['checkBoxLabel'] = isset( $data['checkBoxLabel'] ) ? $data['checkBoxLabel'] : $data['checkBoxLabel'];
123 $order_bump_settings[$key]['highLightText'] = isset( $data['highLightText'] ) ? $data['highLightText'] : $data['highLightText'];
124 $order_bump_settings[$key]['productDescriptionText'] = isset( $data['productDescriptionText'] ) ? $data['productDescriptionText'] : $data['productDescriptionText'];
125 $order_bump_settings[$key]['position'] = isset( $data['position'] ) ? $data['position'] : $data['position'];
126 $order_bump_settings[$key]['selectedStyle'] = isset( $data['selectedStyle'] ) ? $data['selectedStyle'] : $data['selectedStyle'];
127 $order_bump_settings[$key]['productImage'] = isset( $data['productImage'] ) ? $data['productImage'] : $data['productImage'];
128 $order_bump_settings[$key]['isEnabled'] = isset( $data['isEnabled'] ) ? $data['isEnabled'] : $data['isEnabled'];
129
130 }
131 return $order_bump_settings;
132 }
133
134
135 }
136 }
137