PluginProbe
Orderable – Restaurant & Food Ordering System / 1.14.0
Orderable – Restaurant & Food Ordering System v1.14.0
0.1.4 0.1.5 0.2.0 1.0.0 1.1.0 1.1.1 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.19.1 1.19.2 1.2.0 1.20.0 1.20.1 All 44 releases
orderable / inc / modules / checkout / class-checkout.php

class-checkout.php in Orderable – Restaurant & Food Ordering System 1.14.0, at inc/modules/checkout/class-checkout.php

94 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Module: Checkout.
4 *
5 * @package Orderable/Classes
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Checkout module class.
12 */
13 class Orderable_Checkout {
14 /**
15 * Init.
16 */
17 public static function run() {
18 add_filter( 'wpsf_register_settings_orderable', array( __CLASS__, 'register_settings' ) );
19
20 add_action( 'woocommerce_checkout_process', array( __CLASS__, 'is_order_date_valid' ), 5 );
21 }
22
23 /**
24 * Register settings.
25 *
26 * @param array $settings
27 *
28 * @return array
29 */
30 public static function register_settings( $settings = array() ) {
31 $settings['tabs'][] = array(
32 'id' => 'checkout',
33 'title' => __( 'Checkout Settings', 'orderable-pro' ),
34 'priority' => 20,
35 );
36
37 $settings['sections'][] = array(
38 'tab_id' => 'checkout',
39 'section_id' => 'general',
40 'section_title' => __( 'Checkout Settings', 'orderable' ),
41 'section_description' => '',
42 'section_order' => 0,
43 'fields' => array(
44 array(
45 'id' => 'pro',
46 'title' => __( 'Enable Custom Checkout', 'orderable' ),
47 'subtitle' => __( "When enabled, your theme's checkout will be replaced by Orderable's optimized checkout experience.", 'orderable' ),
48 'type' => 'custom',
49 'output' => Orderable_Helpers::get_pro_button( 'checkout' ),
50 ),
51 ),
52 );
53
54 return $settings;
55 }
56
57 /**
58 * Check if the order date is valid.
59 *
60 * The order date is sent via POST.
61 *
62 * @return bool
63 */
64 public static function is_order_date_valid() {
65 // phpcs:ignore WordPress.Security.NonceVerification
66 $order_date = empty( $_POST['orderable_order_date'] ) ? '' : sanitize_text_field( wp_unslash( $_POST['orderable_order_date'] ) );
67
68 if ( empty( $order_date ) || 'asap' === $order_date ) {
69 return true;
70 }
71
72 if ( self::is_order_date_past( $order_date ) ) {
73 wc_add_notice( __( 'Sorry, the date you selected is no longer available. Please choose another.', 'orderable' ), 'error' );
74
75 return false;
76 }
77
78 return true;
79 }
80
81 /**
82 * Check if the given order date is in the past.
83 *
84 * @param int $order_date The order date to be checked in timestamp format.
85 * @return bool Whether the order date is in the past or not.
86 */
87 protected static function is_order_date_past( $order_date ) {
88 $now = new DateTime( 'now', wp_timezone() );
89 $now->setTime( 0, 0, 0 );
90
91 return $order_date < $now->getTimestamp();
92 }
93 }
94