PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / trunk
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster vtrunk
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / admin / class-global-checkout.php

class-global-checkout.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster trunk, at includes/admin/class-global-checkout.php

89 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || die();
4
5 use Sellkit\Global_Checkout\Checkout;
6
7 /**
8 * Sellkit global checkout.
9 *
10 * @since 1.7.4
11 */
12 class Sellkit_Global_Checkout {
13 /**
14 * Class construct.
15 *
16 * @since 1.7.4
17 */
18 public function __construct() {
19 add_action( 'wp_ajax_sellkit_global_checkout_id', [ $this, 'get_global_checkout_funnel_id' ] );
20 add_action( 'wp_ajax_sellkit_global_checkout_toggle_status', [ $this, 'change_status' ] );
21 }
22
23 /**
24 * Get global checkout id.
25 *
26 * @since 1.7.4
27 */
28 public function get_global_checkout_funnel_id() {
29 check_ajax_referer( 'sellkit', 'nonce' );
30
31 $global_checkout_id = get_option( Checkout::SELLKIT_GLOBAL_CHECKOUT_OPTION, 0 );
32
33 // Post not exists.
34 if ( false === get_post_status( $global_checkout_id ) ) {
35 wp_send_json_success( 0 );
36 }
37
38 wp_send_json_success( $global_checkout_id );
39 }
40
41 /**
42 * Set global checkout funnel post status (activate / deactivate).
43 *
44 * Expects POST `status` as the target status: `publish` or `draft`.
45 *
46 * @since 1.7.4
47 */
48 public function change_status() {
49 check_ajax_referer( 'sellkit', 'nonce' );
50
51 $target_status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
52 $post_id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0;
53
54 if ( ! in_array( $target_status, [ 'publish', 'draft' ], true ) || ! $post_id ) {
55 wp_send_json_error( [ 'message' => __( 'Invalid request.', 'sellkit' ) ] );
56 }
57
58 $post = get_post( $post_id );
59
60 if ( ! $post || 'sellkit-funnels' !== $post->post_type ) {
61 wp_send_json_error( [ 'message' => __( 'Invalid funnel.', 'sellkit' ) ] );
62 }
63
64 $global_checkout_id = (int) get_option( Checkout::SELLKIT_GLOBAL_CHECKOUT_OPTION, 0 );
65
66 if ( $global_checkout_id !== $post_id ) {
67 wp_send_json_error( [ 'message' => __( 'Not the Global Checkout funnel.', 'sellkit' ) ] );
68 }
69
70 $updated = wp_update_post(
71 [
72 'ID' => $post_id,
73 'post_status' => $target_status,
74 ],
75 true
76 );
77
78 if ( is_wp_error( $updated ) || ! $updated ) {
79 wp_send_json_error( [ 'message' => __( 'Could not update status.', 'sellkit' ) ] );
80 }
81
82 $saved_status = get_post_status( $post_id );
83
84 wp_send_json_success( $saved_status ? $saved_status : $target_status );
85 }
86 }
87
88 new Sellkit_Global_Checkout();
89