PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.3.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.3.0
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 / woo-dynamic-flow / classes / class-cartflows-wd-flow-actions.php

class-cartflows-wd-flow-actions.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.3.0, at modules/woo-dynamic-flow/classes/class-cartflows-wd-flow-actions.php

115 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Dyanamic Flow Actions
4 *
5 * @package CartFlows
6 */
7
8 /**
9 * Initialization
10 *
11 * @since 1.0.0
12 */
13 class Cartflows_Wd_Flow_Actions {
14
15 /**
16 * Member Variable
17 *
18 * @var instance
19 */
20 private static $instance;
21
22 /**
23 * Initiator
24 */
25 public static function get_instance() {
26 if ( ! isset( self::$instance ) ) {
27 self::$instance = new self();
28 }
29 return self::$instance;
30 }
31
32 /**
33 * Constructor
34 */
35 public function __construct() {
36
37 add_filter( 'cartflows_skip_configure_cart', array( $this, 'skip_cf_cart_configuration' ), 10, 2 );
38
39 add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'add_cf_hidden_fields' ) );
40 add_filter( 'woocommerce_add_to_cart_redirect', array( $this, 'redirect_to_next_flow_step' ), 10, 2 );
41 }
42
43 /**
44 * Skip Configure Cart Data.
45 *
46 * @param bool $skip_cart is skip cart.
47 * @param int $checkout_id checkout id..
48 */
49 public function skip_cf_cart_configuration( $skip_cart, $checkout_id ) {
50
51 if ( isset( $_GET['cf-redirect'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
52 $skip_cart = true;
53 }
54
55 return $skip_cart;
56 }
57
58 /**
59 * Add hidden fields.
60 */
61 public function add_cf_hidden_fields() {
62
63 global $post, $wcf_step;
64
65 if ( $post && $wcf_step ) {
66
67 $flow_id = $wcf_step->get_flow_id();
68 $step_id = $wcf_step->get_step_id();
69
70 echo '<input type="hidden" name="wcf-flow-id" value="' . absint( $flow_id ) . '"/>';
71 echo '<input type="hidden" name="wcf-step-id" value="' . absint( $step_id ) . '"/>';
72 }
73 }
74
75 /**
76 * Redirect to flow next step.
77 *
78 * @param string $redirect_url next step URL.
79 * @param string $product Product adding in cart.
80 */
81 public function redirect_to_next_flow_step( $redirect_url, $product ) {
82
83 if ( isset( $_REQUEST['wcf-step-id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
84
85 $step_id = intval( $_REQUEST['wcf-step-id'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
86
87 if ( CARTFLOWS_STEP_POST_TYPE !== get_post_type( $step_id ) ) {
88 return $redirect_url;
89 }
90
91 $wcf_step_obj = wcf_get_step( $step_id );
92 $next_step_id = $wcf_step_obj->get_direct_next_step_id();
93
94 if ( $next_step_id ) {
95
96 $redirect_url = add_query_arg(
97 array(
98 'cf-redirect' => true,
99 ),
100 get_permalink( $next_step_id )
101 );
102
103 wc_clear_notices();
104 }
105 }
106
107 return $redirect_url;
108 }
109 }
110
111 /**
112 * Kicking this off by calling 'get_instance()' method
113 */
114 Cartflows_Wd_Flow_Actions::get_instance();
115