PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.31.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.31.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Controllers / Web / CheckoutFormsController.php
CheckoutFormsController.php
48 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SureCart\Controllers\Web;
6
7 /**
8 * Handles Checkout related routes.
9 */
10 class CheckoutFormsController {
11
12 /**
13 * Change the mode of the checkout form.
14 */
15 public function changeMode() {
16 $form_post_id = get_query_var( 'sc_checkout_change_mode' );
17 $checkout_post_id = get_query_var( 'sc_checkout_post' );
18 $form_post = get_post( $form_post_id );
19 $checkout_page_post = get_post( $checkout_post_id );
20
21 if ( empty( $form_post ) || empty( $checkout_page_post ) ) {
22 wp_die( esc_html__( 'Invalid request.', 'surecart' ) );
23 }
24
25 $form_block = \SureCart::post()->getFormBlock( $checkout_page_post );
26 if ( ! $form_block ) {
27 wp_die( esc_html__( 'There is no checkout form block on this page.', 'surecart' ) );
28 }
29
30 // Get the mode.
31 $mode = $form_block['attrs']['mode'] ?? 'live';
32
33 // Change the mode.
34 $form_block['attrs']['mode'] = 'test' === $mode ? 'live' : 'test';
35
36 // Update the post.
37 wp_update_post(
38 array(
39 'ID' => $form_post_id,
40 'post_content' => serialize_blocks( [ $form_block ] ),
41 )
42 );
43
44 // Redirect to the checkout page.
45 return \SureCart::redirect()->to( get_permalink( $checkout_post_id ) );
46 }
47 }
48