PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.2.1
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.2.1
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / admin-core / inc / store-checkout.php

store-checkout.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.2.1, at admin-core/inc/store-checkout.php

162 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Store Checkout.
4 *
5 * @package CartFlows
6 */
7
8 namespace CartflowsAdmin\AdminCore\Inc;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class StoreCheckout.
17 */
18 class StoreCheckout {
19 /**
20 * Instance
21 *
22 * @access private
23 * @var object Class object.
24 */
25 private static $instance;
26
27 /**
28 * Initiator
29 *
30 * @return object initialized object of class.
31 */
32 public static function get_instance() {
33 if ( ! isset( self::$instance ) ) {
34 self::$instance = new self();
35 }
36 return self::$instance;
37 }
38
39 /**
40 * Constructor function
41 *
42 * @since X.X.X
43 */
44 public function __construct() {
45 add_filter( 'cartflows_woo_active_steps_data', array( $this, 'store_checkout_import_steps' ) );
46 add_filter( 'cartflows_admin_updated_flow_steps', array( $this, 'update_flow_order' ), 10, 2 );
47 add_filter( 'cartflows_admin_action_slug', array( $this, 'store_action_slug' ), 10, 2 );
48 add_filter( 'cartflows_admin_required_meta_keys', array( $this, 'required_meta_keys' ), 10, 2 );
49 add_filter( 'cartflows_admin_flow_data', array( $this, 'modify_store_checkout_flow_data' ), 10, 2 );
50 add_action( 'cartflows_admin_after_delete_flow', array( $this, 'delete_store_checkout_meta' ), 10, 1 );
51 }
52
53 /**
54 * Steps for store checkout when created from scratch
55 *
56 * @param array $steps existing steps.
57 * @return array
58 * @since X.X.X
59 */
60 public function store_checkout_import_steps( $steps ) {
61 return array(
62 'order-form' => array(
63 'title' => __( 'Checkout (Store)', 'cartflows' ),
64 'type' => 'checkout',
65 ),
66 'order-confirmation' => array(
67 'title' => __( 'Thank You (Store)', 'cartflows' ),
68 'type' => 'thankyou',
69 ),
70 );
71 }
72
73 /**
74 * Updates steps order in flow
75 *
76 * @param array $flows array of updated flow.
77 * @param int $flow_id flow id.
78 * @return array
79 * @since X.X.X
80 */
81 public function update_flow_order( $flows, $flow_id ) {
82 if ( absint( \Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' ) ) !== $flow_id ) {
83 return $flows;
84 }
85
86 $key = array_search( 'thankyou', wp_list_pluck( $flows, 'type' ), true );
87 if ( ! $key ) {
88 return $flows;
89 }
90
91 $thankyou = array_splice( $flows, $key, 1 );
92 $flows[] = $thankyou[0];
93
94 return $flows;
95 }
96
97 /**
98 * Deletes Store Checkout metadata when store checkout is deleted
99 *
100 * @param int $flow_id flow id.
101 * @return void
102 * @since X.X.X
103 */
104 public function delete_store_checkout_meta( $flow_id ) {
105
106 /**
107 * Nonce verification
108 */
109 if ( ! check_ajax_referer( 'cartflows_delete_flow', 'security', false ) ) {
110 $response_data = array( 'message' => __( 'Nonce verification failed.', 'cartflows' ) );
111 wp_send_json_error( $response_data );
112 }
113
114 if ( absint( \Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' ) ) !== $flow_id ) {
115 return;
116 }
117
118 delete_option( '_cartflows_store_checkout' );
119 delete_option( '_cartflows_old_global_checkout' );
120 $common_settings = \Cartflows_Helper::get_common_settings();
121 $common_settings['global_checkout'] = '';
122 $common_settings['override_global_checkout'] = 'disable';
123 AdminHelper::update_admin_settings_option( '_cartflows_common', $common_settings, false );
124 }
125
126 /**
127 * Provides correct action slug for flows / Store Checkout
128 *
129 * @param string $slug actual flow slug 'wcf-edit-flow'.
130 * @param int $flow_id current flow id.
131 * @return string
132 * @since X.X.X
133 */
134 public function store_action_slug( $slug, $flow_id ) {
135 if ( intval( \Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' ) ) === $flow_id ) {
136 $slug = 'wcf-edit-store-step';
137 }
138
139 return $slug;
140 }
141
142 /**
143 * Removing fields not required for store checkout
144 *
145 * @param array $flow_data current $flow_data array.
146 * @param int $flow_id Current flow id.
147 * @return array
148 * @since X.X.X
149 */
150 public function modify_store_checkout_flow_data( $flow_data, $flow_id ) {
151 if ( absint( \Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' ) ) !== $flow_id ) {
152 return $flow_data;
153 }
154
155 unset( $flow_data['settings_data']['settings']['general']['fields']['flow_indexing'] );
156
157 return $flow_data;
158 }
159 }
160
161 StoreCheckout::get_instance();
162