| 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 |
* Toggle global checkout funnel status. |
| 43 |
* |
| 44 |
* @since 1.7.4 |
| 45 |
*/ |
| 46 |
public function change_status() { |
| 47 |
check_ajax_referer( 'sellkit', 'nonce' ); |
| 48 |
|
| 49 |
$status = filter_input( INPUT_POST, 'status', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
| 50 |
$id = filter_input( INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT ); |
| 51 |
$post = get_post( $id ); |
| 52 |
|
| 53 |
$post->post_status = 'draft'; |
| 54 |
|
| 55 |
if ( 'publish' !== $status ) { |
| 56 |
$post->post_status = 'publish'; |
| 57 |
} |
| 58 |
|
| 59 |
$id = wp_update_post( $post ); |
| 60 |
|
| 61 |
wp_send_json_success( $post->post_status ); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
new Sellkit_Global_Checkout(); |
| 66 |
|