PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.2
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.2
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 / modules / gutenberg / classes / class-cartflows-init-blocks.php

class-cartflows-init-blocks.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.1.2, at modules/gutenberg/classes/class-cartflows-init-blocks.php

601 lines 20.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cartflows Blocks Initializer
4 *
5 * Enqueue CSS/JS of all the blocks.
6 *
7 * @since 1.6.15
8 * @package Cartflows
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 /**
16 * Cartflows_Init_Blocks.
17 *
18 * @package Cartflows
19 */
20 class Cartflows_Init_Blocks {
21
22 /**
23 * Member Variable
24 *
25 * @var instance
26 */
27 private static $instance;
28
29 /**
30 * Store Json variable
31 *
32 * @since 1.8.1
33 * @var instance
34 */
35 public static $icon_json;
36
37 /**
38 * Initiator
39 */
40 public static function get_instance() {
41 if ( ! isset( self::$instance ) ) {
42 self::$instance = new self();
43 }
44 return self::$instance;
45 }
46
47 /**
48 * Constructor
49 */
50 public function __construct() {
51
52 // Hook: Frontend assets.
53 add_action( 'enqueue_block_assets', array( $this, 'block_assets' ) );
54
55 // Hook: Editor assets.
56 add_action( 'enqueue_block_editor_assets', array( $this, 'editor_assets' ) );
57
58 if ( version_compare( get_bloginfo( 'version' ), '5.8', '>=' ) ) {
59 add_filter( 'block_categories_all', array( $this, 'register_block_category' ), 10, 2 );
60 } else {
61 add_filter( 'block_categories', array( $this, 'register_block_category' ), 10, 2 );
62 }
63
64 add_action( 'wp_ajax_wpcf_order_detail_form_shortcode', array( $this, 'order_detail_form_shortcode' ) );
65 add_action( 'wp_ajax_wpcf_order_checkout_form_shortcode', array( $this, 'order_checkout_form_shortcode' ) );
66 add_action( 'wp_ajax_wpcf_optin_form_shortcode', array( $this, 'optin_form_shortcode' ) );
67
68 add_filter(
69 'cartflows_show_demo_order_details',
70 function() {
71 return true;
72 }
73 );
74
75 add_action( 'enqueue_block_editor_assets', array( $this, 'add_gcp_vars_to_block_editor' ), 12 );
76
77 // Load the action only if the theme.json file is present in the file.
78 if ( wp_theme_has_theme_json() ) {
79 add_filter( 'wp_theme_json_data_theme', array( $this, 'update_theme_json_file_config' ) );
80 }
81 }
82
83 /**
84 * Add CartFlows GCP css vars to the theme's theme.json file if it is present.
85 *
86 * Use-case: Some themes adds the theme.json file in the theme's root directory. Due to this change, it overrides the default color pallet.
87 * and the filter which are using to add the CSS vars in the Gutenberg does not works and hence, we have to re-add and append it to the theme.json file.
88 *
89 * Note: If theme.json is not present then this filter will not be executed.
90 *
91 * @param WP_Theme_JSON_Data $theme_json_data The Data from the theme.json file.
92 * @return WP_Theme_JSON_Data $theme_json_data Modified data of theme.json file.
93 *
94 * @since 2.0.0
95 */
96 public function update_theme_json_file_config( $theme_json_data ) {
97 $theme_json_data_two = $theme_json_data->get_data();
98
99 $post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
100 $flow_id = wcf()->utils->get_flow_id_from_step_id( $post_id );
101
102 if (
103 ! empty( $flow_id ) &&
104 Cartflows_Helper::is_gcp_styling_enabled( (int) $flow_id ) &&
105 isset( $theme_json_data_two['settings'] ) &&
106 isset( $theme_json_data_two['settings']['color'] )
107 ) {
108
109 $new_color_palette = Cartflows_Helper::generate_css_var_array( $flow_id );
110
111 if ( ! empty( $new_color_palette ) ) {
112 $theme_color_pallet = ! empty( $theme_json_data_two['settings']['color']['palette']['theme'] ) ? $theme_json_data_two['settings']['color']['palette']['theme'] : array();
113 $theme_json_data_two['settings']['color']['palette']['theme'] = ! empty( $theme_color_pallet ) ? array_merge( $theme_color_pallet, $new_color_palette ) : $new_color_palette;
114 }
115 }
116
117 return $theme_json_data->update_with( $theme_json_data_two );
118 }
119
120 /**
121 * Enqueue the Global Color Pallet CSS vars to the page to use in the page builder settings.
122 * This CSS vars needs to be re-added so as to enqueue in the block editor to display the colors in the editor window.
123 *
124 * Note: Currently the GCP support is added for Elementor and Block Builder.
125 *
126 * @since 2.0.0
127 * @return void
128 */
129 public function add_gcp_vars_to_block_editor() {
130
131 // Call the same function which generates the inline styles i:e the CSS VARs with the selected values.
132 wcf()->flow->enqueue_gcp_color_vars( 'CF_block-cartflows-frontend-style' );
133
134 }
135
136 /**
137 * Renders the Order Detail Form shortcode.
138 *
139 * @since 1.6.15
140 */
141 public function order_detail_form_shortcode() {
142
143 check_ajax_referer( 'wpcf_ajax_nonce', 'nonce' );
144
145 if ( ! current_user_can( 'cartflows_manage_flows_steps' ) ) {
146 wp_send_json_error( array( 'message' => __( 'Permission denied.', 'cartflows' ) ) );
147 }
148
149 add_filter(
150 'cartflows_show_demo_order_details',
151 function() {
152 return true;
153 }
154 );
155
156 if ( ! empty( $_POST['thanyouText'] ) ) {
157
158 add_filter(
159 'cartflows_thankyou_meta_wcf-tq-text',
160 function( $text ) {
161 check_ajax_referer( 'wpcf_ajax_nonce', 'nonce' );
162
163 $text = isset( $_POST['thanyouText'] ) ? sanitize_text_field( wp_unslash( $_POST['thanyouText'] ) ) : '';
164
165 return $text;
166 },
167 10,
168 1
169 );
170 }
171
172 add_filter(
173 'cartflows_thankyou_meta_wcf-tq-layout',
174 function( $layout ) {
175 check_ajax_referer( 'wpcf_ajax_nonce', 'nonce' );
176
177 $layout = isset( $_POST['layout'] ) ? sanitize_title( wp_unslash( $_POST['layout'] ) ) : '';
178 return $layout;
179 },
180 10,
181 1
182 );
183
184 $thankyou_id = isset( $_POST['id'] ) ? intval( wp_unslash( $_POST['id'] ) ) : 0;
185 $data['html'] = do_shortcode( '[cartflows_order_details]' );
186 $data['thankyouText'] = wcf()->options->get_thankyou_meta_value( $thankyou_id, 'wcf-tq-text' );
187 $data['layout'] = wcf()->options->get_thankyou_meta_value( $thankyou_id, 'wcf-tq-layout' );
188
189 wp_send_json_success( $data );
190 }
191
192 /**
193 * Renders the Order Checkout Form shortcode.
194 *
195 * @since 1.6.15
196 */
197 public function order_checkout_form_shortcode() {
198 check_ajax_referer( 'wpcf_ajax_nonce', 'nonce' );
199
200 if ( ! current_user_can( 'cartflows_manage_flows_steps' ) ) {
201 wp_send_json_error( array( 'message' => __( 'Permission denied.', 'cartflows' ) ) );
202 }
203
204 add_filter(
205 'cartflows_show_demo_checkout',
206 function() {
207 return true;
208 }
209 );
210
211 if ( isset( $_POST['id'] ) ) {
212 $checkout_id = intval( $_POST['id'] );
213 }
214
215 $store_checkout = intval( \Cartflows_Helper::get_global_setting( '_cartflows_store_checkout' ) );
216
217 $flow_id = wcf()->utils->get_flow_id_from_step_id( $checkout_id );
218
219 if ( ! wcf()->flow->is_flow_testmode( $flow_id ) && ( $store_checkout !== $flow_id ) ) {
220
221 $products = wcf()->utils->get_selected_checkout_products( $checkout_id );
222
223 if ( ! is_array( $products ) || empty( $products[0]['product'] ) ) {
224 wc_clear_notices();
225 wc_add_notice( __( 'No product is selected. Please select products from the checkout meta settings to continue.', 'cartflows' ), 'error' );
226 }
227 }
228 remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form' );
229
230 add_action( 'woocommerce_checkout_order_review', array( Cartflows_Checkout_Markup::get_instance(), 'display_custom_coupon_field' ) );
231
232 $attributes['layout'] = isset( $_POST['layout'] ) ? sanitize_title( wp_unslash( $_POST['layout'] ) ) : '';
233 $attributes['orderBumpSkin'] = isset( $_POST['orderBumpSkin'] ) ? sanitize_title( wp_unslash( $_POST['orderBumpSkin'] ) ) : '';
234 $attributes['orderBumpCheckboxArrow'] = isset( $_POST['orderBumpCheckboxArrow'] ) ? sanitize_title( wp_unslash( $_POST['orderBumpCheckboxArrow'] ) ) : '';
235 $attributes['orderBumpCheckboxArrowAnimation'] = isset( $_POST['orderBumpCheckboxArrowAnimation'] ) ? sanitize_title( wp_unslash( $_POST['orderBumpCheckboxArrowAnimation'] ) ) : '';
236 $attributes['sectionposition'] = isset( $_POST['sectionposition'] ) ? sanitize_title( wp_unslash( $_POST['sectionposition'] ) ) : '';
237 $attributes['productOptionsSkin'] = isset( $_POST['productOptionsSkin'] ) ? sanitize_title( wp_unslash( $_POST['productOptionsSkin'] ) ) : '';
238 $attributes['productOptionsImages'] = isset( $_POST['productOptionsImages'] ) ? sanitize_title( wp_unslash( $_POST['productOptionsImages'] ) ) : '';
239 $attributes['productOptionsSectionTitleText'] = isset( $_POST['productOptionsSectionTitleText'] ) ? sanitize_text_field( wp_unslash( $_POST['productOptionsSectionTitleText'] ) ) : '';
240 $attributes['PreSkipText'] = isset( $_POST['PreSkipText'] ) ? sanitize_title( wp_unslash( $_POST['PreSkipText'] ) ) : '';
241 $attributes['PreOrderText'] = isset( $_POST['PreOrderText'] ) ? sanitize_title( wp_unslash( $_POST['PreOrderText'] ) ) : '';
242 $attributes['PreProductTitleText'] = isset( $_POST['PreProductTitleText'] ) ? sanitize_title( wp_unslash( $_POST['PreProductTitleText'] ) ) : '';
243 $attributes['preSubTitleText'] = isset( $_POST['preSubTitleText'] ) ? sanitize_title( wp_unslash( $_POST['preSubTitleText'] ) ) : '';
244 $attributes['preTitleText'] = isset( $_POST['preTitleText'] ) ? sanitize_title( wp_unslash( $_POST['preTitleText'] ) ) : '';
245 $attributes['PreProductDescText'] = isset( $_POST['PreProductDescText'] ) ? sanitize_title( wp_unslash( $_POST['PreProductDescText'] ) ) : '';
246 $attributes['inputSkins'] = isset( $_POST['inputSkins'] ) ? sanitize_title( wp_unslash( $_POST['inputSkins'] ) ) : '';
247 $attributes['enableNote'] = isset( $_POST['enableNote'] ) ? sanitize_title( wp_unslash( $_POST['enableNote'] ) ) : '';
248 $attributes['noteText'] = isset( $_POST['noteText'] ) ? sanitize_text_field( wp_unslash( $_POST['noteText'] ) ) : '';
249 $attributes['stepOneTitleText'] = isset( $_POST['stepOneTitleText'] ) ? sanitize_text_field( wp_unslash( $_POST['stepOneTitleText'] ) ) : '';
250 $attributes['stepOneSubTitleText'] = isset( $_POST['stepOneSubTitleText'] ) ? sanitize_text_field( wp_unslash( $_POST['stepOneSubTitleText'] ) ) : '';
251 $attributes['stepTwoTitleText'] = isset( $_POST['stepTwoTitleText'] ) ? sanitize_text_field( wp_unslash( $_POST['stepTwoTitleText'] ) ) : '';
252 $attributes['stepTwoSubTitleText'] = isset( $_POST['stepTwoSubTitleText'] ) ? sanitize_text_field( wp_unslash( $_POST['stepTwoSubTitleText'] ) ) : '';
253 $attributes['offerButtonTitleText'] = isset( $_POST['offerButtonTitleText'] ) ? sanitize_text_field( wp_unslash( $_POST['offerButtonTitleText'] ) ) : '';
254 $attributes['offerButtonSubTitleText'] = isset( $_POST['offerButtonSubTitleText'] ) ? sanitize_text_field( wp_unslash( $_POST['offerButtonSubTitleText'] ) ) : '';
255
256 $checkout_fields = array(
257 // Input Fields.
258 array(
259 'filter_slug' => 'wcf-fields-skins',
260 'setting_name' => 'inputSkins',
261 ),
262 array(
263 'filter_slug' => 'wcf-checkout-layout',
264 'setting_name' => 'layout',
265 ),
266 );
267
268 if ( isset( $checkout_fields ) && is_array( $checkout_fields ) ) {
269
270 foreach ( $checkout_fields as $key => $field ) {
271
272 $setting_name = $field['setting_name'];
273
274 if ( '' !== $attributes[ $setting_name ] ) {
275
276 add_filter(
277 'cartflows_checkout_meta_' . $field['filter_slug'],
278 function ( $value ) use ( $setting_name, $attributes ) {
279
280 $value = $attributes[ $setting_name ];
281
282 return $value;
283 },
284 10,
285 1
286 );
287 }
288 }
289 }
290 do_action( 'cartflows_gutenberg_before_checkout_shortcode', $checkout_id );
291
292 do_action( 'cartflows_gutenberg_checkout_options_filters', $attributes );
293
294 do_action( 'cartflows_gutenberg_before_checkout_shortcode' );
295
296 $data['html'] = do_shortcode( '[cartflows_checkout]' );
297
298 wp_send_json_success( $data );
299 }
300
301 /**
302 * Renders the Optin Form shortcode.
303 *
304 * @since 1.6.15
305 */
306 public function optin_form_shortcode() {
307
308 check_ajax_referer( 'wpcf_ajax_nonce', 'nonce' );
309
310 if ( ! current_user_can( 'cartflows_manage_flows_steps' ) ) {
311 wp_send_json_error( array( 'message' => __( 'Permission denied.', 'cartflows' ) ) );
312 }
313
314 add_filter(
315 'cartflows_show_demo_optin_form',
316 function() {
317 return true;
318 }
319 );
320
321 if ( isset( $_POST['id'] ) ) {
322 $optin_id = intval( $_POST['id'] );
323 }
324
325 $products = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-optin-product' );
326 if ( is_array( $products ) && count( $products ) < 1 ) {
327 wc_clear_notices();
328 wc_add_notice( __( 'No product is selected. Please select a Simple, Virtual and Free product from the meta settings.', 'cartflows' ), 'error' );
329 }
330
331 $attributes['input_skins'] = isset( $_POST['input_skins'] ) ? sanitize_title( wp_unslash( $_POST['input_skins'] ) ) : '';
332
333 $optin_fields = array(
334
335 // Input Fields.
336 array(
337 'filter_slug' => 'wcf-input-fields-skins',
338 'setting_name' => 'input_skins',
339 ),
340 );
341
342 if ( isset( $optin_fields ) && is_array( $optin_fields ) ) {
343
344 foreach ( $optin_fields as $key => $field ) {
345
346 $setting_name = $field['setting_name'];
347
348 add_filter(
349 'cartflows_optin_meta_' . $field['filter_slug'],
350 function ( $value ) use ( $setting_name, $attributes ) {
351
352 $value = $attributes[ $setting_name ];
353
354 return $value;
355 },
356 10,
357 1
358 );
359 }
360 }
361
362 do_action( 'cartflows_gutenberg_optin_options_filters', $attributes );
363
364 add_filter( 'woocommerce_cart_needs_payment', '__return_false' );
365 add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
366 add_filter( 'woocommerce_cart_needs_shipping_address', '__return_false' );
367
368 $data['html'] = do_shortcode( '[cartflows_optin]' );
369 $data['buttonText'] = wcf()->options->get_optin_meta_value( $optin_id, 'wcf-submit-button-text' );
370 wp_send_json_success( $data );
371 }
372
373 /**
374 * Enqueue Gutenberg block assets for both frontend + backend.
375 *
376 * @since 1.6.15
377 */
378 public function block_assets() {
379
380 global $post;
381
382 if ( $post && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) {
383
384 // Register block styles for both frontend + backend.
385 wp_enqueue_style(
386 'CF_block-cartflows-style-css', // Handle.
387 CARTFLOWS_URL . 'modules/gutenberg/build/style-blocks.css',
388 is_admin() ? array( 'wp-editor' ) : null, // Dependency to include the CSS after it.
389 CARTFLOWS_VER // filemtime( plugin_dir_path( __DIR__ ) . 'build/style-blocks.css' ) // Version: File modification time.
390 );
391
392 $flow_id = wcf()->utils->get_flow_id_from_step_id( $post->ID );
393
394 // Return if no flow ID is found.
395 if ( empty( $flow_id ) ) {
396 return;
397 }
398
399 if ( Cartflows_Helper::is_gcp_styling_enabled( (int) $flow_id ) ) {
400
401 $gcp_vars = Cartflows_Helper::generate_gcp_css_style( (int) $flow_id );
402
403 // Include the CSS/JS only if the CSS vars are set.
404 if ( ! empty( $gcp_vars ) ) {
405 // Add editor helper css & JS files.
406 wp_enqueue_style( 'wcf-editor-helper-style', CARTFLOWS_URL . 'modules/gutenberg/assets/css/editor-assets.css', array( 'wp-edit-blocks', 'wp-editor' ), CARTFLOWS_VER );
407 wp_enqueue_script( 'wcf-editor-helper-script', CARTFLOWS_URL . 'modules/gutenberg/assets/js/editor-assets.js', array( 'wp-editor', 'jquery' ), CARTFLOWS_VER, true );
408 }
409 }
410 }
411
412 }
413
414 /**
415 * Enqueue assets for both backend.
416 *
417 * @since 1.6.15
418 */
419 public function editor_assets() {
420
421 $post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
422 $post_type = get_post_type( $post_id );
423
424 if ( CARTFLOWS_STEP_POST_TYPE === $post_type ) {
425
426 $wpcf_ajax_nonce = wp_create_nonce( 'wpcf_ajax_nonce' );
427 $step_type = wcf()->utils->get_step_type( $post_id );
428 $show_checkout_pro_opt = apply_filters( 'cartflows_show_checkout_pro_opt', false );
429
430 if ( 'optin' === $step_type && wcf()->is_woo_active ) {
431 wp_enqueue_style( 'wcf-optin-template', wcf()->utils->get_css_url( 'optin-template' ), array( 'wp-edit-blocks' ), CARTFLOWS_VER );
432 }
433 if ( 'checkout' === $step_type && wcf()->is_woo_active ) {
434 wp_enqueue_style( 'wcf-checkout-template', wcf()->utils->get_css_url( 'checkout-template' ), array( 'wp-edit-blocks' ), CARTFLOWS_VER );
435 Cartflows_Checkout_Markup::get_instance()->shortcode_scripts();
436 }
437
438 $script_dep_path = CARTFLOWS_DIR . 'modules/gutenberg/build/blocks.asset.php';
439 $script_info = file_exists( $script_dep_path )
440 ? include $script_dep_path
441 : array(
442 'dependencies' => array(),
443 'version' => CARTFLOWS_VER,
444 );
445 $script_dep = array_merge( $script_info['dependencies'], array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ) );
446 $script_ver = $script_info['version'];
447
448 // Register block editor script for backend.
449 wp_register_script(
450 'CF_block-cartflows-block-js', // Handle.
451 CARTFLOWS_URL . 'modules/gutenberg/build/blocks.js',
452 $script_dep, // Dependencies, defined above.
453 $script_ver, // Version: filemtime — Gets file modification time.
454 true // Enqueue the script in the footer.
455 );
456
457 wp_set_script_translations( 'CF_block-cartflows-block-js', 'cartflows' );
458
459 // Register block editor styles for backend.
460 wp_register_style(
461 'CF_block-cartflows-block-editor-css', // Handle.
462 CARTFLOWS_URL . 'modules/gutenberg/build/blocks.style.css',
463 array( 'wp-edit-blocks' ), // Dependency to include the CSS after it.
464 CARTFLOWS_VER // Version: File modification time.
465 );
466
467 // Common Editor style.
468 wp_enqueue_style(
469 'CF_block-common-editor-css', // Handle.
470 CARTFLOWS_URL . 'modules/gutenberg/dist/editor.css',
471 array( 'wp-edit-blocks' ), // Dependency to include the CSS after it.
472 CARTFLOWS_VER // Version: File modification time.
473 );
474
475 // Enqueue frontend CSS in editor.
476 wp_enqueue_style( 'CF_block-cartflows-frontend-style', CARTFLOWS_URL . 'assets/css/frontend.css', array( 'wp-edit-blocks' ), CARTFLOWS_VER );
477
478 // WP Localized globals. Use dynamic PHP stuff in JavaScript via `cartflowsGlobal` object.
479 wp_localize_script(
480 'CF_block-cartflows-block-js',
481 'cf_blocks_info', // Array containing dynamic data for a JS Global.
482 array(
483 'pluginDirPath' => plugin_dir_path( __DIR__ ),
484 'pluginDirUrl' => plugin_dir_url( __DIR__ ),
485 'category' => 'cartflows',
486 'ajax_url' => admin_url( 'admin-ajax.php' ),
487 'wpcf_ajax_nonce' => $wpcf_ajax_nonce,
488 'blocks' => Cartflows_Block_Config::get_block_attributes(),
489 'tablet_breakpoint' => CF_TABLET_BREAKPOINT,
490 'mobile_breakpoint' => CF_MOBILE_BREAKPOINT,
491 'show_checkout_pro_opt' => $show_checkout_pro_opt,
492 'ID' => $post_id,
493 'step_type' => $step_type,
494 'is_cartflows_pro_install' => _is_cartflows_pro(),
495 'is_woo_active' => wcf()->is_woo_active,
496 'wcf_svg_icons' => $this->backend_load_font_awesome_icons(),
497 'show_product_options' => $this->maybe_show_product_options_for_store_checkout( $post_id ),
498 // Add more data here that you want to access from `cartflowsGlobal` object.
499 )
500 );
501
502 /**
503 * Register Gutenberg block on server-side.
504 *
505 * Register the block on server-side to ensure that the block
506 * scripts and styles for both frontend and backend are
507 * enqueued when the editor loads.
508 *
509 * @link https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type#enqueuing-block-scripts
510 * @since 1.6.15
511 */
512 register_block_type(
513 'wcfb/next-step-button',
514 array(
515 // Enqueue blocks.js in the editor only.
516 'editor_script' => 'CF_block-cartflows-block-js',
517 // Enqueue blocks.css in the editor only.
518 'style' => 'CF_block-cartflows-block-editor-css',
519 // Enqueue blocks.commoneditorstyle.build.css in the editor only.
520 'editor_style' => 'CF_block-common-editor-css',
521 )
522 );
523
524 }
525 }
526
527 /**
528 * Maybe show product options.
529 *
530 * @param int $step_id step id.
531 * @return bool
532 */
533 public function maybe_show_product_options_for_store_checkout( $step_id ) {
534
535 $flow_id = (int) wcf()->utils->get_flow_id_from_step_id( $step_id );
536 $store_checkout = intval( get_option( '_cartflows_store_checkout', false ) );
537
538 if ( $flow_id !== $store_checkout ) {
539 return true;
540
541 }
542
543 if ( $flow_id === $store_checkout && Cartflows_Helper::display_product_tab_in_store_checkout() ) {
544 return true;
545 }
546
547 return false;
548
549 }
550
551 /**
552 * Get Json Data.
553 *
554 * @since 1.8.1
555 * @return Array
556 */
557 public function backend_load_font_awesome_icons() {
558
559 $json_file = CARTFLOWS_DIR . 'modules/gutenberg/src/controls/spectra-icons-v6.php';
560
561 if ( ! file_exists( $json_file ) ) {
562 return array();
563 }
564
565 // Function has already run.
566 if ( null !== self::$icon_json ) {
567 return self::$icon_json;
568 }
569
570 self::$icon_json = include $json_file;
571
572 return self::$icon_json;
573 }
574
575 /**
576 * Gutenberg block category for WCFB.
577 *
578 * @param array $categories Block categories.
579 * @param object $post Post object.
580 * @since 1.6.15
581 */
582 public function register_block_category( $categories, $post ) {
583 return array_merge(
584 $categories,
585 array(
586 array(
587 'slug' => 'cartflows',
588 'title' => __( 'Cartflows', 'cartflows' ),
589 ),
590 )
591 );
592 }
593
594 }
595
596 /**
597 * Prepare if class 'Cartflows_Init_Blocks' exist.
598 * Kicking this off by calling 'get_instance()' method
599 */
600 Cartflows_Init_Blocks::get_instance();
601