| 1 |
<?php |
| 2 |
/** |
| 3 |
* Woo hooks for compatibility. Data processed for performance. |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
/** |
| 13 |
* Class for elementor page builder compatibility |
| 14 |
*/ |
| 15 |
class Cartflows_Woo_Hooks { |
| 16 |
|
| 17 |
/** |
| 18 |
* Member Variable |
| 19 |
* |
| 20 |
* @var instance |
| 21 |
*/ |
| 22 |
private static $instance; |
| 23 |
|
| 24 |
/** |
| 25 |
* Member Variable |
| 26 |
* |
| 27 |
* @var instance |
| 28 |
*/ |
| 29 |
public static $ajax_data = array(); |
| 30 |
|
| 31 |
/** |
| 32 |
* Initiator |
| 33 |
*/ |
| 34 |
public static function get_instance() { |
| 35 |
if ( ! isset( self::$instance ) ) { |
| 36 |
self::$instance = new self(); |
| 37 |
} |
| 38 |
return self::$instance; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Constructor |
| 43 |
*/ |
| 44 |
public function __construct() { |
| 45 |
|
| 46 |
add_action( 'wp', array( $this, 'register_wc_hooks' ), 10 ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Rgister wc hookes for elementor preview mode |
| 51 |
*/ |
| 52 |
public function register_wc_hooks() { |
| 53 |
|
| 54 |
// Using global variable on WordPress hooks.Hence ignoring nonce verification. |
| 55 |
if ( isset( $_GET['wc-ajax'] ) && 'update_order_review' === $_GET['wc-ajax'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 56 |
$post_data = array(); |
| 57 |
|
| 58 |
$post_raw_data = isset( $_POST['post_data'] ) ? sanitize_text_field( wp_unslash( $_POST['post_data'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 59 |
|
| 60 |
parse_str( $post_raw_data, $post_data ); |
| 61 |
|
| 62 |
self::$ajax_data = $post_data; |
| 63 |
|
| 64 |
do_action( 'cartflows_woo_checkout_update_order_review_init', self::$ajax_data ); |
| 65 |
|
| 66 |
/* Woocommerce update order action */ |
| 67 |
add_action( 'woocommerce_checkout_update_order_review', array( $this, 'update_order_review_hook' ) ); |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Update order review hook |
| 74 |
* |
| 75 |
* @param string $post_raw_data post data. |
| 76 |
*/ |
| 77 |
public function update_order_review_hook( $post_raw_data ) { |
| 78 |
|
| 79 |
do_action( 'cartflows_woo_checkout_update_order_review', self::$ajax_data ); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Kicking this off by calling 'get_instance()' method |
| 85 |
*/ |
| 86 |
Cartflows_Woo_Hooks::get_instance(); |
| 87 |
|