From c3cde2ae9bcad269e0b23c09fcddb21883d271de Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Wed, 18 Nov 2026 18:00:07 +0600 Subject: [PATCH 01/13] address require Field added --- ecommerce/BillingController.php | 11 +++++--- ecommerce/CheckoutController.php | 4 +++ ecommerce/OptionKeys.php | 3 +++ .../Paypal/src/Payments/Paypal/Helper.php | 6 ++--- .../Paypal/src/Payments/Paypal/Paypal.php | 10 +++---- ecommerce/Settings.php | 27 +++++++++++++++++++ templates/ecommerce/billing-form-fields.php | 18 +++++++------ .../checkout-billing-form-fields.php | 7 ++--- 8 files changed, 64 insertions(+), 22 deletions(-) diff --git a/ecommerce/BillingController.php b/ecommerce/BillingController.php index 65ee5bb5b2..0fed5f3d8d 100644 --- a/ecommerce/BillingController.php +++ b/ecommerce/BillingController.php @@ -238,14 +238,19 @@ protected function validate( array $data ) { 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', - 'phone' => 'required', - 'zip_code' => 'required', - 'address' => 'required', + 'phone' => '', + 'zip_code' => '', + 'address' => '', 'country' => 'required', 'state' => 'required', 'city' => 'required', ); + if ( Settings::is_billing_address_required() ) { + $validation_rules['billing_address'] = 'required'; + $data['billing_address'] = trim( (string) ( $data['billing_address'] ?? '' ) ); + } + // Skip validation rules for not available fields in data. foreach ( $validation_rules as $key => $value ) { if ( ! array_key_exists( $key, $data ) ) { diff --git a/ecommerce/CheckoutController.php b/ecommerce/CheckoutController.php index 74fe3a9806..18ade1d748 100644 --- a/ecommerce/CheckoutController.php +++ b/ecommerce/CheckoutController.php @@ -593,6 +593,10 @@ public function pay_now() { $billing_fillable_fields = array_intersect_key( $request, array_flip( $billing_model->get_fillable_fields() ) ); + if ( Settings::is_billing_address_required() && '' === trim( (string) ( $billing_fillable_fields['billing_address'] ?? '' ) ) ) { + array_push( $errors, __( 'Billing address is required', 'tutor' ) ); + } + $order_payment_fields = array( 'object_ids', 'coupon_code', diff --git a/ecommerce/OptionKeys.php b/ecommerce/OptionKeys.php index e473e82dcb..d5ad3fd040 100644 --- a/ecommerce/OptionKeys.php +++ b/ecommerce/OptionKeys.php @@ -35,6 +35,9 @@ class OptionKeys { const BILLING_PHONE_NUMBER = 'billing_phone_number'; const BILLING_EMAIL = 'billing_email'; + // Whether the billing address field is required. + const IS_BILLING_ADDRESS_REQUIRED = 'is_billing_address_required'; + // Ecommerce Policies. const PRIVACY_POLICY = 'ecommerce_privacy_policy'; diff --git a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php index 6382bdcf12..a900f865dd 100644 --- a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php +++ b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php @@ -265,14 +265,14 @@ function ( $message, $issue ) { * @since 4.2.0 Uses Utils::splitAddress() instead of System::splitAddress(). */ public static function getShippingInfo( $shipping ): array { - [$address1, $address2] = Utils::splitAddress( $shipping, 300 ); + $address = Utils::splitAddress( $shipping, 300 ); return array( 'type' => 'SHIPPING', 'name' => array( 'full_name' => $shipping->name ), 'address' => array( - 'address_line_1' => $address1, - 'address_line_2' => $address2, + 'address_line_1' => $address[0] ?? '', + 'address_line_2' => $address[1] ?? '', 'admin_area_2' => $shipping->city, 'admin_area_1' => $shipping->region, 'postal_code' => $shipping->postal_code, diff --git a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php index a5cac57fe3..7236acc165 100644 --- a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php +++ b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php @@ -157,11 +157,11 @@ public function prepareData( $data ): array { $returnData = array( 'purchase_units' => array( array( - 'custom_id' => $data->order_id, - 'items' => $items, - 'amount' => $amount, - 'payee' => array( 'email_address' => $this->config->get( 'merchant_email' ) ), - 'description' => $description, + 'custom_id' => $data->order_id, + 'items' => $items, + 'amount' => $amount, + 'payee' => array( 'email_address' => $this->config->get( 'merchant_email' ) ), + 'soft_descriptor' => $description, ), ), 'intent' => 'CAPTURE', diff --git a/ecommerce/Settings.php b/ecommerce/Settings.php index ae825e30b2..8703f36c24 100644 --- a/ecommerce/Settings.php +++ b/ecommerce/Settings.php @@ -58,6 +58,26 @@ public static function is_coupon_usage_enabled() { return (bool) tutor_utils()->get_option( OptionKeys::IS_COUPON_APPLICABLE, false ); } + /** + * Check whether the billing address field is required. + * + * @since 4.0.0 + * + * @return boolean + */ + public static function is_billing_address_required() { + $is_required = (bool) tutor_utils()->get_option( OptionKeys::IS_BILLING_ADDRESS_REQUIRED, true ); + + /** + * Filters whether the billing address field is required. + * + * @since 4.0.0 + * + * @param bool $is_required Whether the billing address is required. + */ + return (bool) apply_filters( 'tutor_is_billing_address_required', $is_required ); + } + /** * Add ecommerce settings * @@ -239,6 +259,13 @@ public static function add_ecommerce_settings( $fields ) { 'default' => 'off', 'desc' => __( 'Allow users to purchase courses directly without adding them to the cart.', 'tutor' ), ), + array( + 'key' => OptionKeys::IS_BILLING_ADDRESS_REQUIRED, + 'type' => 'toggle_switch', + 'label' => __( 'Require Billing Address', 'tutor' ), + 'default' => 'on', + 'desc' => __( 'Make the address related field (Postcode/Zip, Address) mandatory in the checkout billing form. Turn off to make it optional.', 'tutor' ), + ), ), ), ), diff --git a/templates/ecommerce/billing-form-fields.php b/templates/ecommerce/billing-form-fields.php index 53bb7ce8ff..8c052bfa3a 100644 --- a/templates/ecommerce/billing-form-fields.php +++ b/templates/ecommerce/billing-form-fields.php @@ -23,12 +23,14 @@ use Tutor\Components\Constants\Variant; use Tutor\Components\Constants\InputType; use Tutor\Components\InputField; +use Tutor\Ecommerce\Settings; use TUTOR\Icon; -$show_close_button = $show_close_button ?? false; -$close_action = $close_action ?? 'editBilling = false'; -$country_options = $country_options ?? array(); -$initial_states = $initial_states ?? array(); +$show_close_button = $show_close_button ?? false; +$close_action = $close_action ?? 'editBilling = false'; +$country_options = $country_options ?? array(); +$initial_states = $initial_states ?? array(); +$is_address_required = Settings::is_billing_address_required(); ?> @@ -98,7 +100,7 @@ ->id( 'billing_phone' ) ->required() ->placeholder( __( 'Enter your phone number', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_phone', { required: true })" ) + ->attr( 'x-bind', "register('billing_phone')" ) ->render(); InputField::make() @@ -143,7 +145,7 @@ ->id( 'billing_zip_code' ) ->required() ->placeholder( __( 'Enter your postcode/ zip', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_zip_code', { required: true })" ) + ->attr( 'x-bind', "register('billing_zip_code')" ) ->render(); ?> @@ -155,8 +157,8 @@ ->name( 'billing_address' ) ->label( __( 'Address', 'tutor' ) ) ->id( 'billing_address' ) - ->required() + ->required( $is_address_required ) ->placeholder( __( 'Enter your address', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_address', { required: true })" ) + ->attr( 'x-bind', $is_address_required ? "register('billing_address', { required: true })" : "register('billing_address')" ) ->render(); ?> diff --git a/templates/ecommerce/checkout-billing-form-fields.php b/templates/ecommerce/checkout-billing-form-fields.php index 4187ade127..356274ddc5 100644 --- a/templates/ecommerce/checkout-billing-form-fields.php +++ b/templates/ecommerce/checkout-billing-form-fields.php @@ -10,6 +10,7 @@ */ use Tutor\Ecommerce\BillingController; +use Tutor\Ecommerce\Settings; $billing_controller = new BillingController( false ); $billing_info = $billing_controller->get_billing_info(); @@ -111,7 +112,7 @@ - + @@ -120,7 +121,7 @@ - + @@ -129,7 +130,7 @@ - + > From 21ea3945f05562578ef65a5e50584729832f0f47 Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Thu, 19 Nov 2026 10:47:20 +0600 Subject: [PATCH 02/13] Removed shipping part from paypal --- .../Paypal/src/Payments/Paypal/Helper.php | 28 ------------------- .../Paypal/src/Payments/Paypal/Paypal.php | 4 --- 2 files changed, 32 deletions(-) diff --git a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php index a900f865dd..65a7606956 100644 --- a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php +++ b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php @@ -253,34 +253,6 @@ function ( $message, $issue ) { return $final_message; } - /** - * Creates the shipping information array for a payment request. - * - * This method constructs and returns an array containing the shipping type, receiver's full name, - * and address for a payment request. - * - * @param object $shipping The shipping data containing the receiver's name and address. - * @return array The formatted shipping information including type, name, and address. - * @since 3.0.0 - * @since 4.2.0 Uses Utils::splitAddress() instead of System::splitAddress(). - */ - public static function getShippingInfo( $shipping ): array { - $address = Utils::splitAddress( $shipping, 300 ); - - return array( - 'type' => 'SHIPPING', - 'name' => array( 'full_name' => $shipping->name ), - 'address' => array( - 'address_line_1' => $address[0] ?? '', - 'address_line_2' => $address[1] ?? '', - 'admin_area_2' => $shipping->city, - 'admin_area_1' => $shipping->region, - 'postal_code' => $shipping->postal_code, - 'country_code' => $shipping->country->alpha_2, - ), - ); - } - /** * Retrieves the URL from an array of links that matches a specified condition. * diff --git a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php index 7236acc165..cde360f75b 100644 --- a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php +++ b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php @@ -176,10 +176,6 @@ public function prepareData( $data ): array { Helper::getPaymentSourceForRecurring( $returnData, $this->previousPayload ); } - if ( isset( $data->shipping_address ) && ! empty( $data->shipping_address ) ) { - $returnData['purchase_units'][0]['shipping'] = Helper::getShippingInfo( $data->shipping_address ); - } - return $returnData; } From 36ad8491b292417541c2f78121963887b2d763ae Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Thu, 19 Nov 2026 15:37:40 +0600 Subject: [PATCH 03/13] functionalities added for required billing field option. --- ecommerce/BillingController.php | 10 ++--- ecommerce/CheckoutController.php | 6 +-- ecommerce/Settings.php | 42 +++++++++---------- templates/ecommerce/billing-form-fields.php | 7 ++-- .../checkout-billing-form-fields.php | 7 +++- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/ecommerce/BillingController.php b/ecommerce/BillingController.php index 52dfe55b03..32fb571230 100644 --- a/ecommerce/BillingController.php +++ b/ecommerce/BillingController.php @@ -260,23 +260,21 @@ public function get_billing_info( $user_id = 0 ) { */ protected function validate( array $data ) { + $is_billing_address_required = Settings::is_billing_address_required(); + $validation_rules = array( 'user_id' => 'required|numeric', 'billing_first_name' => 'required', 'billing_last_name' => 'required', 'billing_email' => 'required|email', 'billing_phone' => '', - 'billing_zip_code' => '', - 'billing_address' => '', + 'billing_zip_code' => $is_billing_address_required ? 'required' : '', + 'billing_address' => $is_billing_address_required ? 'required' : '', 'billing_country' => 'required', 'billing_state' => 'required', 'billing_city' => 'required', ); - if ( Settings::is_billing_address_required() ) { - $validation_rules['billing_address'] = 'required'; - } - // Countries without states have nothing to select. if ( ! $this->model->country_has_states( wp_unslash( $data['billing_country'] ?? '' ) ) ) { unset( $validation_rules['billing_state'] ); diff --git a/ecommerce/CheckoutController.php b/ecommerce/CheckoutController.php index 0b831671cd..ce327782f2 100644 --- a/ecommerce/CheckoutController.php +++ b/ecommerce/CheckoutController.php @@ -598,10 +598,6 @@ public function pay_now() { $billing_fillable_fields = array_intersect_key( $request, array_flip( $billing_model->get_fillable_fields() ) ); - if ( Settings::is_billing_address_required() && '' === trim( (string) ( $billing_fillable_fields['billing_address'] ?? '' ) ) ) { - array_push( $errors, __( 'Billing address is required', 'tutor' ) ); - } - $order_payment_fields = array( 'object_ids', 'coupon_code', @@ -1303,4 +1299,4 @@ public function get_courses_data_by_order_items( $order_items ): array { ), ); } -} \ No newline at end of file +} diff --git a/ecommerce/Settings.php b/ecommerce/Settings.php index 8703f36c24..76adb1442f 100644 --- a/ecommerce/Settings.php +++ b/ecommerce/Settings.php @@ -58,26 +58,6 @@ public static function is_coupon_usage_enabled() { return (bool) tutor_utils()->get_option( OptionKeys::IS_COUPON_APPLICABLE, false ); } - /** - * Check whether the billing address field is required. - * - * @since 4.0.0 - * - * @return boolean - */ - public static function is_billing_address_required() { - $is_required = (bool) tutor_utils()->get_option( OptionKeys::IS_BILLING_ADDRESS_REQUIRED, true ); - - /** - * Filters whether the billing address field is required. - * - * @since 4.0.0 - * - * @param bool $is_required Whether the billing address is required. - */ - return (bool) apply_filters( 'tutor_is_billing_address_required', $is_required ); - } - /** * Add ecommerce settings * @@ -264,7 +244,7 @@ public static function add_ecommerce_settings( $fields ) { 'type' => 'toggle_switch', 'label' => __( 'Require Billing Address', 'tutor' ), 'default' => 'on', - 'desc' => __( 'Make the address related field (Postcode/Zip, Address) mandatory in the checkout billing form. Turn off to make it optional.', 'tutor' ), + 'desc' => __( 'Make billing address fields (Address, Postcode/ZIP) mandatory at checkout. Turn off to make them optional.', 'tutor' ), ), ), ), @@ -531,4 +511,24 @@ public static function get_paypal_config_fields() { return $config_fields; } + + /** + * Check whether the billing address field is required. + * + * @since 4.3.0 + * + * @return boolean + */ + public static function is_billing_address_required() { + $is_required = (bool) tutor_utils()->get_option( OptionKeys::IS_BILLING_ADDRESS_REQUIRED, true ); + + /** + * Filters whether the billing address field is required. + * + * @since 4.3.0 + * + * @param bool $is_required Whether the billing address is required. + */ + return (bool) apply_filters( 'tutor_is_billing_address_required', $is_required ); + } } diff --git a/templates/ecommerce/billing-form-fields.php b/templates/ecommerce/billing-form-fields.php index 8c052bfa3a..4be85ddacd 100644 --- a/templates/ecommerce/billing-form-fields.php +++ b/templates/ecommerce/billing-form-fields.php @@ -31,6 +31,7 @@ $country_options = $country_options ?? array(); $initial_states = $initial_states ?? array(); $is_address_required = Settings::is_billing_address_required(); +$required_option = $is_address_required ? ', { required: true }' : ''; ?> @@ -136,7 +137,7 @@ ->id( 'billing_city' ) ->required() ->placeholder( __( 'Enter your city', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_city', { required: true })" ) + ->attr( 'x-bind', "register('billing_city' $required_option)" ) ->render(); InputField::make() @@ -145,7 +146,7 @@ ->id( 'billing_zip_code' ) ->required() ->placeholder( __( 'Enter your postcode/ zip', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_zip_code')" ) + ->attr( 'x-bind', "register('billing_zip_code' $required_option)" ) ->render(); ?> @@ -159,6 +160,6 @@ ->id( 'billing_address' ) ->required( $is_address_required ) ->placeholder( __( 'Enter your address', 'tutor' ) ) - ->attr( 'x-bind', $is_address_required ? "register('billing_address', { required: true })" : "register('billing_address')" ) + ->attr( 'x-bind', "register('billing_address' $required_option)" ) ->render(); ?> diff --git a/templates/ecommerce/checkout-billing-form-fields.php b/templates/ecommerce/checkout-billing-form-fields.php index 356274ddc5..354221a6cb 100644 --- a/templates/ecommerce/checkout-billing-form-fields.php +++ b/templates/ecommerce/checkout-billing-form-fields.php @@ -27,6 +27,9 @@ $country_info = tutor_get_country_info_by_name( $billing_country ); $states = $country_info && isset( $country_info['states'] ) ? $country_info['states'] : array(); + +$is_address_required = Settings::is_billing_address_required(); +$required_option = $is_address_required ? 'required' : ''; ?>
@@ -112,7 +115,7 @@ - + >
@@ -130,7 +133,7 @@ - > + > From 8afc6faabc6b9471af1e2bb0cadafe816720f32b Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Fri, 20 Nov 2026 10:29:24 +0600 Subject: [PATCH 04/13] removed soft descriptor from paypal as user can see it. --- .../Paypal/src/Payments/Paypal/Paypal.php | 17 ++++------------- templates/ecommerce/billing-form-fields.php | 7 +++---- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php index cde360f75b..26b3c46677 100644 --- a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php +++ b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Paypal.php @@ -145,23 +145,14 @@ public function prepareData( $data ): array { $items = 'one-time' === $type ? Helper::getItems( $data ) : null; $amount = 'one-time' === $type ? Helper::createAmountData( $data ) : Helper::createAmountForRecurring( $data ); $tutor_metadata = Utils::prepareMerchantMetadata( $data->order_user_id, $this->config->get( 'mode' ) ); - $description = implode( - ',', - array_map( - fn ( $key, $value ) => "{$key}: {$value}", - array_keys( $tutor_metadata ), - $tutor_metadata - ) - ); $returnData = array( 'purchase_units' => array( array( - 'custom_id' => $data->order_id, - 'items' => $items, - 'amount' => $amount, - 'payee' => array( 'email_address' => $this->config->get( 'merchant_email' ) ), - 'soft_descriptor' => $description, + 'custom_id' => $data->order_id, + 'items' => $items, + 'amount' => $amount, + 'payee' => array( 'email_address' => $this->config->get( 'merchant_email' ) ), ), ), 'intent' => 'CAPTURE', diff --git a/templates/ecommerce/billing-form-fields.php b/templates/ecommerce/billing-form-fields.php index 4be85ddacd..265c5014c5 100644 --- a/templates/ecommerce/billing-form-fields.php +++ b/templates/ecommerce/billing-form-fields.php @@ -99,7 +99,6 @@ ->name( 'billing_phone' ) ->label( __( 'Phone', 'tutor' ) ) ->id( 'billing_phone' ) - ->required() ->placeholder( __( 'Enter your phone number', 'tutor' ) ) ->attr( 'x-bind', "register('billing_phone')" ) ->render(); @@ -135,16 +134,16 @@ ->name( 'billing_city' ) ->label( __( 'City', 'tutor' ) ) ->id( 'billing_city' ) - ->required() + ->required( $is_address_required ) ->placeholder( __( 'Enter your city', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_city' $required_option)" ) + ->attr( 'x-bind', "register('billing_city', { required: true })" ) ->render(); InputField::make() ->name( 'billing_zip_code' ) ->label( __( 'Postcode/ Zip', 'tutor' ) ) ->id( 'billing_zip_code' ) - ->required() + ->required( $is_address_required ) ->placeholder( __( 'Enter your postcode/ zip', 'tutor' ) ) ->attr( 'x-bind', "register('billing_zip_code' $required_option)" ) ->render(); From fc79c7f5580d5f273e731f15bf8a689da752577c Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Fri, 20 Nov 2026 12:48:36 +0600 Subject: [PATCH 05/13] Pattern attr added for billing fields --- ecommerce/BillingController.php | 136 +++++++++++++++++- ecommerce/CheckoutController.php | 9 ++ templates/ecommerce/billing-form-fields.php | 16 +-- .../checkout-billing-form-fields.php | 12 +- 4 files changed, 158 insertions(+), 15 deletions(-) diff --git a/ecommerce/BillingController.php b/ecommerce/BillingController.php index 32fb571230..63e9477752 100644 --- a/ecommerce/BillingController.php +++ b/ecommerce/BillingController.php @@ -287,7 +287,16 @@ protected function validate( array $data ) { } } - return ValidationHelper::validate( $validation_rules, $data ); + $validation = ValidationHelper::validate( $validation_rules, $data ); + + // Format checks run only on fields that passed the rules above. + $format_errors = array_diff_key( self::validate_field_formats( $data ), $validation->errors ); + if ( ! empty( $format_errors ) ) { + $validation->errors = array_merge( $validation->errors, $format_errors ); + $validation->success = false; + } + + return $validation; } /** @@ -356,4 +365,129 @@ public static function get_default_values() { return $default_values; } + + /** + * Allowed character formats for billing fields. + * + * @since 4.3.0 + * + * @return array + */ + public static function get_field_formats(): array { + // Matches one or more letters (any language), combining marks, spaces, apostrophes, dots, or hyphens. + $name_pattern = "[\\p{L}\\p{M}\\s'.\\-]+"; + + $formats = array( + 'billing_first_name' => array( + 'pattern' => $name_pattern, + 'message' => __( 'First name can only contain letters, spaces, apostrophes, dots and hyphens.', 'tutor' ), + ), + 'billing_last_name' => array( + 'pattern' => $name_pattern, + 'message' => __( 'Last name can only contain letters, spaces, apostrophes, dots and hyphens.', 'tutor' ), + ), + 'billing_phone' => array( + 'pattern' => '\\+?[0-9\\s\\(\\)\\-]{6,20}', + 'message' => __( 'Phone can only contain digits, spaces, parentheses, hyphens and a leading +.', 'tutor' ), + ), + 'billing_city' => array( + 'pattern' => $name_pattern, + 'message' => __( 'City can only contain letters, spaces, apostrophes, periods and hyphens.', 'tutor' ), + ), + 'billing_zip_code' => array( + 'pattern' => '[A-Za-z0-9\\s\\-]{2,12}', + 'message' => __( 'Postcode/ZIP can only contain letters, digits, spaces and hyphens.', 'tutor' ), + ), + 'billing_address' => array( + 'pattern' => "[\\p{L}\\p{M}\\p{N}\\s,.#'\\/\\(\\)\\-]+", + 'message' => __( 'Address can only contain letters, digits, spaces and , . # / \' ( ) -', 'tutor' ), + ), + ); + + /** + * Filters the allowed character formats for billing fields. + * + * @since 4.3.0 + * + * @param array $formats Field name => array( 'pattern' => string, 'message' => string ). + */ + return apply_filters( 'tutor_billing_field_formats', $formats ); + } + + /** + * Print HTML `pattern` and `title` attributes for a billing input. + * + * @since 4.3.0 + * + * @param string $field Billing field name. + * + * @return void + */ + public static function render_pattern_attrs( string $field ): void { + $formats = self::get_field_formats(); + if ( ! isset( $formats[ $field ] ) ) { + return; + } + + printf( + ' pattern="%s" title="%s"', + esc_attr( $formats[ $field ]['pattern'] ), + esc_attr( $formats[ $field ]['message'] ) + ); + } + + /** + * Check billing values against their allowed formats. + * + * @since 4.3.0 + * + * @param array $data Unslashed billing data keyed by field name. + * + * @return array Errors keyed by field name. + */ + public static function validate_field_formats( array $data ): array { + $errors = array(); + + foreach ( self::get_field_formats() as $field => $format ) { + $value = trim( (string) ( $data[ $field ] ?? '' ) ); + if ( '' === $value ) { + continue; + } + + if ( ! preg_match( '~^(?:' . $format['pattern'] . ')$~u', $value ) ) { + $errors[ $field ][] = $format['message']; + } + } + + return $errors; + } + + /** + * Build the client-side validation rules passed to the form's register() call. + * + * @since 4.3.0 + * + * @param string $field Billing field name. + * @param bool $required Whether the field is required. + * + * @return string JavaScript object literal, such as "{ required: true, pattern: {...} }". + */ + public static function get_client_rules( string $field, bool $required ): string { + $rules = array(); + $formats = self::get_field_formats(); + + if ( $required ) { + $rules[] = 'required: true'; + } + + if ( isset( $formats[ $field ] ) ) { + $rules[] = sprintf( + "pattern: { value: /^(?:%s)$/u, message: '%s' }", + $formats[ $field ]['pattern'], + esc_js( $formats[ $field ]['message'] ) + ); + } + + return '{ ' . implode( ', ', $rules ) . ' }'; + } } diff --git a/ecommerce/CheckoutController.php b/ecommerce/CheckoutController.php index ce327782f2..165225abe2 100644 --- a/ecommerce/CheckoutController.php +++ b/ecommerce/CheckoutController.php @@ -598,6 +598,10 @@ public function pay_now() { $billing_fillable_fields = array_intersect_key( $request, array_flip( $billing_model->get_fillable_fields() ) ); + foreach ( BillingController::validate_field_formats( $billing_fillable_fields ) as $field_errors ) { + array_push( $errors, ...$field_errors ); + } + $order_payment_fields = array( 'object_ids', 'coupon_code', @@ -1161,6 +1165,11 @@ public function pay_incomplete_order() { exit; } + $format_errors = BillingController::validate_field_formats( $billing_fillable_fields ); + if ( ! empty( $format_errors ) ) { + tutor_redirect_after_payment( OrderModel::ORDER_PLACEMENT_FAILED, $order_id, implode( ' ', array_merge( ...array_values( $format_errors ) ) ) ); + } + if ( $order_id ) { $order_model = new OrderModel(); $order_data = $order_model->get_order_by_id( $order_id ); diff --git a/templates/ecommerce/billing-form-fields.php b/templates/ecommerce/billing-form-fields.php index 265c5014c5..8987f8cebd 100644 --- a/templates/ecommerce/billing-form-fields.php +++ b/templates/ecommerce/billing-form-fields.php @@ -23,6 +23,7 @@ use Tutor\Components\Constants\Variant; use Tutor\Components\Constants\InputType; use Tutor\Components\InputField; +use Tutor\Ecommerce\BillingController; use Tutor\Ecommerce\Settings; use TUTOR\Icon; @@ -31,7 +32,6 @@ $country_options = $country_options ?? array(); $initial_states = $initial_states ?? array(); $is_address_required = Settings::is_billing_address_required(); -$required_option = $is_address_required ? ', { required: true }' : ''; ?> @@ -70,7 +70,7 @@ ->id( 'billing_first_name' ) ->required() ->placeholder( __( 'Enter your first name', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_first_name', { required: true })" ) + ->attr( 'x-bind', "register('billing_first_name', " . BillingController::get_client_rules( 'billing_first_name', true ) . ')' ) ->render(); InputField::make() @@ -79,7 +79,7 @@ ->id( 'billing_last_name' ) ->required() ->placeholder( __( 'Enter your last name', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_last_name', { required: true })" ) + ->attr( 'x-bind', "register('billing_last_name', " . BillingController::get_client_rules( 'billing_last_name', true ) . ')' ) ->render(); ?> @@ -100,7 +100,7 @@ ->label( __( 'Phone', 'tutor' ) ) ->id( 'billing_phone' ) ->placeholder( __( 'Enter your phone number', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_phone')" ) + ->attr( 'x-bind', "register('billing_phone', " . BillingController::get_client_rules( 'billing_phone', false ) . ')' ) ->render(); InputField::make() @@ -134,9 +134,9 @@ ->name( 'billing_city' ) ->label( __( 'City', 'tutor' ) ) ->id( 'billing_city' ) - ->required( $is_address_required ) + ->required() ->placeholder( __( 'Enter your city', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_city', { required: true })" ) + ->attr( 'x-bind', "register('billing_city', " . BillingController::get_client_rules( 'billing_city', true ) . ')' ) ->render(); InputField::make() @@ -145,7 +145,7 @@ ->id( 'billing_zip_code' ) ->required( $is_address_required ) ->placeholder( __( 'Enter your postcode/ zip', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_zip_code' $required_option)" ) + ->attr( 'x-bind', "register('billing_zip_code', " . BillingController::get_client_rules( 'billing_zip_code', $is_address_required ) . ')' ) ->render(); ?> @@ -159,6 +159,6 @@ ->id( 'billing_address' ) ->required( $is_address_required ) ->placeholder( __( 'Enter your address', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_address' $required_option)" ) + ->attr( 'x-bind', "register('billing_address', " . BillingController::get_client_rules( 'billing_address', $is_address_required ) . ')' ) ->render(); ?> diff --git a/templates/ecommerce/checkout-billing-form-fields.php b/templates/ecommerce/checkout-billing-form-fields.php index 354221a6cb..e1078032fa 100644 --- a/templates/ecommerce/checkout-billing-form-fields.php +++ b/templates/ecommerce/checkout-billing-form-fields.php @@ -38,7 +38,7 @@ - + > @@ -47,7 +47,7 @@ - + > @@ -106,7 +106,7 @@ - + > @@ -115,7 +115,7 @@ - > + > @@ -124,7 +124,7 @@ - + > @@ -133,7 +133,7 @@ - > + > From 76db0a3a66185acca94093cc360d23dfe4b71227 Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Fri, 20 Nov 2026 16:08:26 +0600 Subject: [PATCH 06/13] Issue fixed subscription billing field not showing error message. --- ecommerce/BillingController.php | 80 +------------------------ ecommerce/CheckoutController.php | 4 +- models/BillingModel.php | 100 ++++++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 80 deletions(-) diff --git a/ecommerce/BillingController.php b/ecommerce/BillingController.php index 63e9477752..7e4fb5588c 100644 --- a/ecommerce/BillingController.php +++ b/ecommerce/BillingController.php @@ -290,7 +290,7 @@ protected function validate( array $data ) { $validation = ValidationHelper::validate( $validation_rules, $data ); // Format checks run only on fields that passed the rules above. - $format_errors = array_diff_key( self::validate_field_formats( $data ), $validation->errors ); + $format_errors = array_diff_key( BillingModel::validate_field_formats( $data ), $validation->errors ); if ( ! empty( $format_errors ) ) { $validation->errors = array_merge( $validation->errors, $format_errors ); $validation->success = false; @@ -366,54 +366,6 @@ public static function get_default_values() { return $default_values; } - /** - * Allowed character formats for billing fields. - * - * @since 4.3.0 - * - * @return array - */ - public static function get_field_formats(): array { - // Matches one or more letters (any language), combining marks, spaces, apostrophes, dots, or hyphens. - $name_pattern = "[\\p{L}\\p{M}\\s'.\\-]+"; - - $formats = array( - 'billing_first_name' => array( - 'pattern' => $name_pattern, - 'message' => __( 'First name can only contain letters, spaces, apostrophes, dots and hyphens.', 'tutor' ), - ), - 'billing_last_name' => array( - 'pattern' => $name_pattern, - 'message' => __( 'Last name can only contain letters, spaces, apostrophes, dots and hyphens.', 'tutor' ), - ), - 'billing_phone' => array( - 'pattern' => '\\+?[0-9\\s\\(\\)\\-]{6,20}', - 'message' => __( 'Phone can only contain digits, spaces, parentheses, hyphens and a leading +.', 'tutor' ), - ), - 'billing_city' => array( - 'pattern' => $name_pattern, - 'message' => __( 'City can only contain letters, spaces, apostrophes, periods and hyphens.', 'tutor' ), - ), - 'billing_zip_code' => array( - 'pattern' => '[A-Za-z0-9\\s\\-]{2,12}', - 'message' => __( 'Postcode/ZIP can only contain letters, digits, spaces and hyphens.', 'tutor' ), - ), - 'billing_address' => array( - 'pattern' => "[\\p{L}\\p{M}\\p{N}\\s,.#'\\/\\(\\)\\-]+", - 'message' => __( 'Address can only contain letters, digits, spaces and , . # / \' ( ) -', 'tutor' ), - ), - ); - - /** - * Filters the allowed character formats for billing fields. - * - * @since 4.3.0 - * - * @param array $formats Field name => array( 'pattern' => string, 'message' => string ). - */ - return apply_filters( 'tutor_billing_field_formats', $formats ); - } - /** * Print HTML `pattern` and `title` attributes for a billing input. * @@ -424,7 +376,7 @@ public static function get_field_formats(): array { * @return void */ public static function render_pattern_attrs( string $field ): void { - $formats = self::get_field_formats(); + $formats = BillingModel::get_field_formats(); if ( ! isset( $formats[ $field ] ) ) { return; } @@ -436,32 +388,6 @@ public static function render_pattern_attrs( string $field ): void { ); } - /** - * Check billing values against their allowed formats. - * - * @since 4.3.0 - * - * @param array $data Unslashed billing data keyed by field name. - * - * @return array Errors keyed by field name. - */ - public static function validate_field_formats( array $data ): array { - $errors = array(); - - foreach ( self::get_field_formats() as $field => $format ) { - $value = trim( (string) ( $data[ $field ] ?? '' ) ); - if ( '' === $value ) { - continue; - } - - if ( ! preg_match( '~^(?:' . $format['pattern'] . ')$~u', $value ) ) { - $errors[ $field ][] = $format['message']; - } - } - - return $errors; - } - /** * Build the client-side validation rules passed to the form's register() call. * @@ -474,7 +400,7 @@ public static function validate_field_formats( array $data ): array { */ public static function get_client_rules( string $field, bool $required ): string { $rules = array(); - $formats = self::get_field_formats(); + $formats = BillingModel::get_field_formats(); if ( $required ) { $rules[] = 'required: true'; diff --git a/ecommerce/CheckoutController.php b/ecommerce/CheckoutController.php index 165225abe2..3d82ed1e21 100644 --- a/ecommerce/CheckoutController.php +++ b/ecommerce/CheckoutController.php @@ -598,7 +598,7 @@ public function pay_now() { $billing_fillable_fields = array_intersect_key( $request, array_flip( $billing_model->get_fillable_fields() ) ); - foreach ( BillingController::validate_field_formats( $billing_fillable_fields ) as $field_errors ) { + foreach ( BillingModel::validate_field_formats( $billing_fillable_fields ) as $field_errors ) { array_push( $errors, ...$field_errors ); } @@ -1165,7 +1165,7 @@ public function pay_incomplete_order() { exit; } - $format_errors = BillingController::validate_field_formats( $billing_fillable_fields ); + $format_errors = BillingModel::validate_field_formats( $billing_fillable_fields ); if ( ! empty( $format_errors ) ) { tutor_redirect_after_payment( OrderModel::ORDER_PLACEMENT_FAILED, $order_id, implode( ' ', array_merge( ...array_values( $format_errors ) ) ) ); } diff --git a/models/BillingModel.php b/models/BillingModel.php index 393a83d098..706561d9d6 100644 --- a/models/BillingModel.php +++ b/models/BillingModel.php @@ -12,6 +12,7 @@ use Tutor\Core\DB; use Tutor\Core\Input; +use Tutor\Ecommerce\Settings; use Tutor\Helpers\QueryHelper; /** @@ -65,6 +66,18 @@ class BillingModel { 'billing_state', ); + /** + * Billing fields that are not required during validation. + * + * @since 4.3.0 + * + * @var string[] + */ + private $optional_fields = array( + 'billing_zip_code', + 'billing_address', + 'billing_phone', + ); /** * Get fillable fields * @@ -162,7 +175,13 @@ public function get_info( $user_id ) { * @return bool */ public function has_complete_billing_info( array $data ) { - foreach ( $this->get_required_fields() as $field ) { + $required_fields = $this->required_fields; + $is_address_required = Settings::is_billing_address_required(); + if ( ! $is_address_required ) { + $required_fields = array_diff( $this->required_fields, $this->optional_fields ); + } + + foreach ( $required_fields as $field ) { if ( 'billing_state' === $field && ! $this->country_has_states( $data['billing_country'] ?? '' ) ) { continue; } @@ -172,6 +191,11 @@ public function has_complete_billing_info( array $data ) { } } + $format_errors = self::validate_field_formats( $data ); + if ( ! empty( $format_errors ) ) { + return false; + } + return true; } @@ -234,4 +258,78 @@ public function country_has_states( string $country ) { public function get_partial_update_fields() { return $this->partial_update_fields; } + + /** + * Check billing values against their allowed formats. + * + * @since 4.3.0 + * + * @param array $data Un-slashed billing data keyed by field name. + * + * @return array Errors keyed by field name. + */ + public static function validate_field_formats( array $data ): array { + $errors = array(); + + foreach ( self::get_field_formats() as $field => $format ) { + $value = trim( (string) ( $data[ $field ] ?? '' ) ); + if ( '' === $value ) { + continue; + } + + if ( ! preg_match( '~^(?:' . $format['pattern'] . ')$~u', $value ) ) { + $errors[ $field ][] = $format['message']; + } + } + + return $errors; + } + + /** + * Allowed character formats for billing fields. + * + * @since 4.3.0 + * + * @return array + */ + public static function get_field_formats(): array { + // Matches one or more letters (any language), combining marks, spaces, apostrophes, dots, or hyphens. + $name_pattern = "[\\p{L}\\p{M}\\s'.\\-]+"; + + $formats = array( + 'billing_first_name' => array( + 'pattern' => $name_pattern, + 'message' => __( 'First name can only contain letters, spaces, apostrophes, dots and hyphens.', 'tutor' ), + ), + 'billing_last_name' => array( + 'pattern' => $name_pattern, + 'message' => __( 'Last name can only contain letters, spaces, apostrophes, dots and hyphens.', 'tutor' ), + ), + 'billing_phone' => array( + 'pattern' => '\\+?[0-9\\s\\(\\)\\-]{6,20}', + 'message' => __( 'Phone can only contain digits, spaces, parentheses, hyphens and a leading +.', 'tutor' ), + ), + 'billing_city' => array( + 'pattern' => "[\\p{L}\\p{M}\\p{N}\\s'.\\-]+", + 'message' => __( 'City can only contain letters, spaces, apostrophes, dots, numbers and hyphens.', 'tutor' ), + ), + 'billing_zip_code' => array( + 'pattern' => '[A-Za-z0-9\\s\\-]{2,12}', + 'message' => __( 'Postcode/ZIP can only contain letters, digits, spaces and hyphens.', 'tutor' ), + ), + 'billing_address' => array( + 'pattern' => "[\\p{L}\\p{M}\\p{N}\\s,.#&'\\/\\(\\)\\-]+", + 'message' => __( 'Address can only contain letters, digits, spaces and , . # / \' ( ) -', 'tutor' ), + ), + ); + + /** + * Filters the allowed character formats for billing fields. + * + * @since 4.3.0 + * + * @param array $formats Field name => array( 'pattern' => string, 'message' => string ). + */ + return apply_filters( 'tutor_billing_field_formats', $formats ); + } } From 9a9ea7ddc27bfb56b81e22460f7522ec294de9ef Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Fri, 20 Nov 2026 17:11:37 +0600 Subject: [PATCH 07/13] Paypal shipping address removed from recurring. --- .../Paypal/src/Payments/Paypal/Helper.php | 29 ++----------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php index 65a7606956..4850774e02 100644 --- a/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php +++ b/ecommerce/PaymentGateways/Paypal/src/Payments/Paypal/Helper.php @@ -310,8 +310,7 @@ private static function built_payment_source_from_vault( $previous_payload ): ?a return null; } - $paypal_source = $vault_details->payment_source->paypal; - $shipping_address = $paypal_source->shipping->address; + $paypal_source = $vault_details->payment_source->paypal; return array( 'paypal' => array( @@ -329,32 +328,10 @@ private static function built_payment_source_from_vault( $previous_payload ): ?a 'experience_context' => array( 'payment_method_preference' => 'IMMEDIATE_PAYMENT_REQUIRED', ), - 'address' => self::format_address( $shipping_address ), ), ); } - /** - * Format a shipping address object into an associative array. - * - * @since 3.9.0 - * - * @param object $shipping_address The PayPal shipping address object. - * - * @return array The formatted address as an associative array. - */ - private static function format_address( $shipping_address ): array { - - return array( - 'address_line_1' => $shipping_address->address_line_1, - 'address_line_2' => $shipping_address->address_line_2, - 'admin_area_1' => $shipping_address->admin_area_1 ?? '', - 'admin_area_2' => $shipping_address->admin_area_2 ?? '', - 'postal_code' => $shipping_address->postal_code, - 'country_code' => $shipping_address->country_code, - ); - } - /** * Build a PayPal payment source array using order details. * @@ -374,8 +351,7 @@ private static function built_payment_source_from_order_details( $previous_paylo return null; } - $paypal_source = $order_details->payment_source->paypal; - $shipping_address = $order_details->purchase_units[0]->shipping->address; + $paypal_source = $order_details->payment_source->paypal; return array( 'paypal' => array( @@ -393,7 +369,6 @@ private static function built_payment_source_from_order_details( $previous_paylo 'experience_context' => array( 'payment_method_preference' => 'IMMEDIATE_PAYMENT_REQUIRED', ), - 'address' => self::format_address( $shipping_address ), ), ); } From 1199a2401b95327eec6325a9a62740516cd9d9e1 Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Mon, 23 Nov 2026 10:41:02 +0600 Subject: [PATCH 08/13] removed unnecessary changes --- docs/developer/testing.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/developer/testing.md b/docs/developer/testing.md index c7a8da6bc4..afe619ebc0 100644 --- a/docs/developer/testing.md +++ b/docs/developer/testing.md @@ -132,9 +132,9 @@ pnpm run test:e2e:debug ## Troubleshooting -| Problem | Fix | -| ------------------------------------ | ------------------------------------------------------------------------------------------------------- | -| `wp-config.php is missing` | Run the installer from inside the plugin directory (`wp-content/plugins/tutor`) of a WordPress install. | -| Database connection failed | Make sure MySQL is running and the `WP_TEST_DB_*` values in `.env` are correct. | -| Tests hit the live database | Check that the database routing block above is present in `wp-config.php`. | -| Need to undo `wp-config.php` changes | Restore `wp-config.php.bak`. | +| Problem | Fix | +| ------------------------------------------ | -------------------------------------------------------------------------------------------------------- | +| `wp-config.php is missing` | Run the installer from inside the plugin directory (`wp-content/plugins/tutor`) of a WordPress install. | +| Database connection failed | Make sure MySQL is running and the `WP_TEST_DB_*` values in `.env` are correct. | +| Tests hit the live database | Check that the database routing block above is present in `wp-config.php`. | +| Need to undo `wp-config.php` changes | Restore `wp-config.php.bak`. | From 0c0909ee0b25addc6872d9afa706e74be4564bbe Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Fri, 27 Nov 2026 17:01:01 +0600 Subject: [PATCH 09/13] added options for all billing address field. --- ecommerce/OptionKeys.php | 16 +++++++++++--- ecommerce/Settings.php | 47 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/ecommerce/OptionKeys.php b/ecommerce/OptionKeys.php index d5ad3fd040..0d7bcadf77 100644 --- a/ecommerce/OptionKeys.php +++ b/ecommerce/OptionKeys.php @@ -35,9 +35,6 @@ class OptionKeys { const BILLING_PHONE_NUMBER = 'billing_phone_number'; const BILLING_EMAIL = 'billing_email'; - // Whether the billing address field is required. - const IS_BILLING_ADDRESS_REQUIRED = 'is_billing_address_required'; - // Ecommerce Policies. const PRIVACY_POLICY = 'ecommerce_privacy_policy'; @@ -47,6 +44,19 @@ class OptionKeys { const BUY_NOW = 'is_enable_buy_now'; + /** + * Whether the billing address fields are required. + * + * @since 4.3.0 + */ + const IS_BILLING_COUNTRY_REQUIRED = 'is_billing_country_required'; + const IS_BILLING_STATE_REQUIRED = 'is_billing_state_required'; + const IS_BILLING_CITY_REQUIRED = 'is_billing_city_required'; + const IS_BILLING_ZIP_CODE_REQUIRED = 'is_billing_zip_code_required'; + const IS_BILLING_PHONE_REQUIRED = 'is_billing_phone_required'; + const IS_BILLING_ADDRESS_REQUIRED = 'is_billing_address_required'; + + /** * Get billing field options * diff --git a/ecommerce/Settings.php b/ecommerce/Settings.php index 76adb1442f..4e6f7b5ea9 100644 --- a/ecommerce/Settings.php +++ b/ecommerce/Settings.php @@ -239,12 +239,55 @@ public static function add_ecommerce_settings( $fields ) { 'default' => 'off', 'desc' => __( 'Allow users to purchase courses directly without adding them to the cart.', 'tutor' ), ), + ), + ), + array( + 'label' => __( 'Billing Address Configuration', 'tutor' ), + 'desc' => __( 'Customize your billing address field to suit your preferences.', 'tutor' ), + 'slug' => 'billing_address_configuration', + 'block_type' => 'uniform', + 'fields' => array( + array( + 'key' => OptionKeys::IS_BILLING_COUNTRY_REQUIRED, + 'type' => 'toggle_switch', + 'label' => __( 'Country Required', 'tutor' ), + 'default' => 'on', + 'desc' => __( 'Require users to select a country.', 'tutor' ), + ), + array( + 'key' => OptionKeys::IS_BILLING_STATE_REQUIRED, + 'type' => 'toggle_switch', + 'label' => __( 'State Required', 'tutor' ), + 'default' => 'on', + 'desc' => __( 'Require users to select a state.', 'tutor' ), + ), + array( + 'key' => OptionKeys::IS_BILLING_CITY_REQUIRED, + 'type' => 'toggle_switch', + 'label' => __( 'City Required', 'tutor' ), + 'default' => 'on', + 'desc' => __( 'Require users to add a city.', 'tutor' ), + ), + array( + 'key' => OptionKeys::IS_BILLING_ZIP_CODE_REQUIRED, + 'type' => 'toggle_switch', + 'label' => __( 'Postal/ZIP Code Required', 'tutor' ), + 'default' => 'on', + 'desc' => __( 'Require users to add postal/zip code.', 'tutor' ), + ), + array( + 'key' => OptionKeys::IS_BILLING_PHONE_REQUIRED, + 'type' => 'toggle_switch', + 'label' => __( 'Phone Number Required', 'tutor' ), + 'default' => 'on', + 'desc' => __( 'Require users to add phone number.', 'tutor' ), + ), array( 'key' => OptionKeys::IS_BILLING_ADDRESS_REQUIRED, 'type' => 'toggle_switch', - 'label' => __( 'Require Billing Address', 'tutor' ), + 'label' => __( 'Address Required', 'tutor' ), 'default' => 'on', - 'desc' => __( 'Make billing address fields (Address, Postcode/ZIP) mandatory at checkout. Turn off to make them optional.', 'tutor' ), + 'desc' => __( 'Require users to add address.', 'tutor' ), ), ), ), From 64353b15f8e1fc0b5b7a26a32606ab3dfc008c61 Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Fri, 27 Nov 2026 18:01:08 +0600 Subject: [PATCH 10/13] billing field condition added in other related file. --- ecommerce/BillingController.php | 12 ++-- ecommerce/CheckoutController.php | 2 +- ecommerce/Settings.php | 53 ++++++++++++++++ models/BillingModel.php | 62 +++++++++++-------- templates/ecommerce/billing-form-fields.php | 24 ++++--- .../checkout-billing-form-fields.php | 15 ++--- 6 files changed, 117 insertions(+), 51 deletions(-) diff --git a/ecommerce/BillingController.php b/ecommerce/BillingController.php index e4bb5b563f..b4eace4fb1 100644 --- a/ecommerce/BillingController.php +++ b/ecommerce/BillingController.php @@ -260,21 +260,17 @@ public function get_billing_info( $user_id = 0 ) { */ protected function validate( array $data ) { - $is_billing_address_required = Settings::is_billing_address_required(); - $validation_rules = array( 'user_id' => 'required|numeric', 'billing_first_name' => 'required', 'billing_last_name' => 'required', 'billing_email' => 'required|email', - 'billing_phone' => '', - 'billing_zip_code' => $is_billing_address_required ? 'required' : '', - 'billing_address' => $is_billing_address_required ? 'required' : '', - 'billing_country' => 'required', - 'billing_state' => 'required', - 'billing_city' => 'required', ); + foreach ( array_keys( Settings::get_configurable_billing_fields() ) as $field ) { + $validation_rules[ $field ] = Settings::is_billing_field_required( $field ) ? 'required' : ''; + } + // Countries without states have nothing to select. if ( ! $this->model->country_has_states( wp_unslash( $data['billing_country'] ?? '' ) ) ) { unset( $validation_rules['billing_state'] ); diff --git a/ecommerce/CheckoutController.php b/ecommerce/CheckoutController.php index 7fb64298a9..e9ced20509 100644 --- a/ecommerce/CheckoutController.php +++ b/ecommerce/CheckoutController.php @@ -640,7 +640,7 @@ protected function validate_pay_now_request( array $request, int $current_user_i $validation = ValidationHelper::validate( $validation_rules, $request ); - foreach ( BillingModel::validate_field_formats( $billing_validation_rules ) as $field_errors ) { + foreach ( BillingModel::validate_field_formats( $request ) as $field_errors ) { array_push( $errors, ...$field_errors ); } diff --git a/ecommerce/Settings.php b/ecommerce/Settings.php index 4e6f7b5ea9..d2c6396446 100644 --- a/ecommerce/Settings.php +++ b/ecommerce/Settings.php @@ -574,4 +574,57 @@ public static function is_billing_address_required() { */ return (bool) apply_filters( 'tutor_is_billing_address_required', $is_required ); } + + /** + * Billing fields whose required state is controlled by a setting, + * mapped to their option key. + * + * @since 4.3.0 + * + * @return array + */ + public static function get_configurable_billing_fields() { + return array( + 'billing_country' => OptionKeys::IS_BILLING_COUNTRY_REQUIRED, + 'billing_state' => OptionKeys::IS_BILLING_STATE_REQUIRED, + 'billing_city' => OptionKeys::IS_BILLING_CITY_REQUIRED, + 'billing_zip_code' => OptionKeys::IS_BILLING_ZIP_CODE_REQUIRED, + 'billing_phone' => OptionKeys::IS_BILLING_PHONE_REQUIRED, + 'billing_address' => OptionKeys::IS_BILLING_ADDRESS_REQUIRED, + ); + } + + /** + * Check whether a billing field is required. + * + * First name, last name and email are always required. The other fields + * follow their "Billing Address Configuration" setting. + * + * @since 4.3.0 + * + * @param string $field Billing field name, such as billing_city. + * + * @return boolean + */ + public static function is_billing_field_required( string $field ) { + $fields = self::get_configurable_billing_fields(); + + if ( ! isset( $fields[ $field ] ) ) { + $is_required = in_array( $field, array( 'billing_first_name', 'billing_last_name', 'billing_email' ), true ); + } elseif ( 'billing_address' === $field ) { + $is_required = self::is_billing_address_required(); + } else { + $is_required = (bool) tutor_utils()->get_option( $fields[ $field ], true ); + } + + /** + * Filters whether a billing field is required. + * + * @since 4.3.0 + * + * @param bool $is_required Whether the field is required. + * @param string $field Billing field name. + */ + return (bool) apply_filters( 'tutor_is_billing_fields_required', $is_required, $field ); + } } diff --git a/models/BillingModel.php b/models/BillingModel.php index c636ca25e0..d024f16f14 100644 --- a/models/BillingModel.php +++ b/models/BillingModel.php @@ -66,18 +66,6 @@ class BillingModel { 'billing_state', ); - /** - * Billing fields that are not required during validation. - * - * @since 4.3.0 - * - * @var string[] - */ - private $optional_fields = array( - 'billing_zip_code', - 'billing_address', - 'billing_phone', - ); /** * Get fillable fields * @@ -106,16 +94,36 @@ public function get_required_fields() { public function get_validation_rules() { /** * The `billing_state` field is excluded because not all countries have states. + * It is checked by validate_billing_location(). */ - return array( + $rules = array( 'billing_first_name' => 'required', 'billing_last_name' => 'required', 'billing_email' => 'required|email', - 'billing_phone' => 'required', - 'billing_zip_code' => 'required', - 'billing_address' => 'required', - 'billing_country' => 'required', - 'billing_city' => 'required', + ); + + foreach ( array( 'billing_phone', 'billing_zip_code', 'billing_address', 'billing_country', 'billing_city' ) as $field ) { + $rules[ $field ] = Settings::is_billing_field_required( $field ) ? 'required' : ''; + } + + return $rules; + } + + /** + * Get the billing fields that are required by the current settings. + * + * @since 4.3.0 + * + * @return string[] + */ + public function get_active_required_fields() { + return array_values( + array_filter( + $this->required_fields, + function ( $field ) { + return Settings::is_billing_field_required( $field ); + } + ) ); } @@ -133,6 +141,11 @@ public function get_validation_rules() { * @return string[] List of error messages, empty when valid. */ public function validate_billing_location( string $country, string $state ): array { + // An optional country may be left empty, but then a state makes no sense. + if ( '' === $country && ! Settings::is_billing_field_required( 'billing_country' ) ) { + return '' === $state ? array() : array( __( 'Invalid state', 'tutor' ) ); + } + $country_info = tutor_get_country_info_by_name( $country ); if ( ! $country_info ) { @@ -141,6 +154,11 @@ public function validate_billing_location( string $country, string $state ): arr $state_names = array_column( $country_info['states'] ?? array(), 'name' ); + // An optional state may be left empty. + if ( '' === $state && ! Settings::is_billing_field_required( 'billing_state' ) ) { + return array(); + } + // Countries without states don't require one. if ( ! empty( $state_names ) && ! in_array( $state, $state_names, true ) ) { return array( __( 'Invalid state', 'tutor' ) ); @@ -228,13 +246,7 @@ public function get_info( $user_id ) { * @return bool */ public function has_complete_billing_info( array $data ) { - $required_fields = $this->required_fields; - $is_address_required = Settings::is_billing_address_required(); - if ( ! $is_address_required ) { - $required_fields = array_diff( $this->required_fields, $this->optional_fields ); - } - - foreach ( $required_fields as $field ) { + foreach ( $this->get_active_required_fields() as $field ) { if ( 'billing_state' === $field && ! $this->country_has_states( $data['billing_country'] ?? '' ) ) { continue; } diff --git a/templates/ecommerce/billing-form-fields.php b/templates/ecommerce/billing-form-fields.php index 8987f8cebd..7816d598b1 100644 --- a/templates/ecommerce/billing-form-fields.php +++ b/templates/ecommerce/billing-form-fields.php @@ -31,7 +31,10 @@ $close_action = $close_action ?? 'editBilling = false'; $country_options = $country_options ?? array(); $initial_states = $initial_states ?? array(); -$is_address_required = Settings::is_billing_address_required(); +$required = array(); +foreach ( array( 'billing_phone', 'billing_country', 'billing_state', 'billing_city', 'billing_zip_code', 'billing_address' ) as $billing_field ) { + $required[ $billing_field ] = Settings::is_billing_field_required( $billing_field ); +} ?> @@ -99,8 +102,9 @@ ->name( 'billing_phone' ) ->label( __( 'Phone', 'tutor' ) ) ->id( 'billing_phone' ) + ->required( $required['billing_phone'] ) ->placeholder( __( 'Enter your phone number', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_phone', " . BillingController::get_client_rules( 'billing_phone', false ) . ')' ) + ->attr( 'x-bind', "register('billing_phone', " . BillingController::get_client_rules( 'billing_phone', $required['billing_phone'] ) . ')' ) ->render(); InputField::make() @@ -110,9 +114,9 @@ ->options( $country_options ) ->searchable() ->id( 'billing_country' ) - ->required() + ->required( $required['billing_country'] ) ->placeholder( __( 'Enter your country', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_country', { required: true })" ) + ->attr( 'x-bind', "register('billing_country', " . BillingController::get_client_rules( 'billing_country', $required['billing_country'] ) . ')' ) ->render(); InputField::make() @@ -134,18 +138,18 @@ ->name( 'billing_city' ) ->label( __( 'City', 'tutor' ) ) ->id( 'billing_city' ) - ->required() + ->required( $required['billing_city'] ) ->placeholder( __( 'Enter your city', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_city', " . BillingController::get_client_rules( 'billing_city', true ) . ')' ) + ->attr( 'x-bind', "register('billing_city', " . BillingController::get_client_rules( 'billing_city', $required['billing_city'] ) . ')' ) ->render(); InputField::make() ->name( 'billing_zip_code' ) ->label( __( 'Postcode/ Zip', 'tutor' ) ) ->id( 'billing_zip_code' ) - ->required( $is_address_required ) + ->required( $required['billing_zip_code'] ) ->placeholder( __( 'Enter your postcode/ zip', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_zip_code', " . BillingController::get_client_rules( 'billing_zip_code', $is_address_required ) . ')' ) + ->attr( 'x-bind', "register('billing_zip_code', " . BillingController::get_client_rules( 'billing_zip_code', $required['billing_zip_code'] ) . ')' ) ->render(); ?> @@ -157,8 +161,8 @@ ->name( 'billing_address' ) ->label( __( 'Address', 'tutor' ) ) ->id( 'billing_address' ) - ->required( $is_address_required ) + ->required( $required['billing_address'] ) ->placeholder( __( 'Enter your address', 'tutor' ) ) - ->attr( 'x-bind', "register('billing_address', " . BillingController::get_client_rules( 'billing_address', $is_address_required ) . ')' ) + ->attr( 'x-bind', "register('billing_address', " . BillingController::get_client_rules( 'billing_address', $required['billing_address'] ) . ')' ) ->render(); ?> diff --git a/templates/ecommerce/checkout-billing-form-fields.php b/templates/ecommerce/checkout-billing-form-fields.php index e1078032fa..fa68d989ba 100644 --- a/templates/ecommerce/checkout-billing-form-fields.php +++ b/templates/ecommerce/checkout-billing-form-fields.php @@ -28,8 +28,9 @@ $country_info = tutor_get_country_info_by_name( $billing_country ); $states = $country_info && isset( $country_info['states'] ) ? $country_info['states'] : array(); -$is_address_required = Settings::is_billing_address_required(); -$required_option = $is_address_required ? 'required' : ''; +$required_attr = function ( $field ) { + return Settings::is_billing_field_required( $field ) ? 'required' : ''; +}; ?>
@@ -64,7 +65,7 @@ - > - > + >
@@ -115,7 +116,7 @@ - > + > @@ -124,7 +125,7 @@ - > + > @@ -133,7 +134,7 @@ - > + > From 5e6474acf7a1fce85d75bb9103096543b073e848 Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Mon, 30 Nov 2026 13:31:32 +0600 Subject: [PATCH 11/13] Code simplification --- ecommerce/BillingController.php | 4 +- ecommerce/CheckoutController.php | 8 +-- ecommerce/Settings.php | 65 +++++++------------ models/BillingModel.php | 71 +++++++++++++-------- templates/ecommerce/billing-form-fields.php | 13 ++-- 5 files changed, 75 insertions(+), 86 deletions(-) diff --git a/ecommerce/BillingController.php b/ecommerce/BillingController.php index b4eace4fb1..70184cba72 100644 --- a/ecommerce/BillingController.php +++ b/ecommerce/BillingController.php @@ -267,8 +267,8 @@ protected function validate( array $data ) { 'billing_email' => 'required|email', ); - foreach ( array_keys( Settings::get_configurable_billing_fields() ) as $field ) { - $validation_rules[ $field ] = Settings::is_billing_field_required( $field ) ? 'required' : ''; + foreach ( Settings::get_required_billing_fields() as $field => $is_required ) { + $validation_rules[ $field ] = $is_required ? 'required' : ''; } // Countries without states have nothing to select. diff --git a/ecommerce/CheckoutController.php b/ecommerce/CheckoutController.php index e9ced20509..0f577a7fd6 100644 --- a/ecommerce/CheckoutController.php +++ b/ecommerce/CheckoutController.php @@ -640,17 +640,13 @@ protected function validate_pay_now_request( array $request, int $current_user_i $validation = ValidationHelper::validate( $validation_rules, $request ); - foreach ( BillingModel::validate_field_formats( $request ) as $field_errors ) { - array_push( $errors, ...$field_errors ); - } - if ( $validation->success ) { // Validate the billing country and state to prevent tax reduction abuse. $errors = array_merge( $errors, $this->billing_model->validate_billing_location( - $request['billing_country'], - $request['billing_state'] + $request['billing_country'] ?? '', + $request['billing_state'] ?? '' ) ); diff --git a/ecommerce/Settings.php b/ecommerce/Settings.php index d2c6396446..d06fc2f0a3 100644 --- a/ecommerce/Settings.php +++ b/ecommerce/Settings.php @@ -556,28 +556,32 @@ public static function get_paypal_config_fields() { } /** - * Check whether the billing address field is required. + * Check whether a billing field is required. + * + * First name, last name and email are always required. The other fields + * follow their "Billing Address Configuration" setting. * * @since 4.3.0 * + * @param string $field Billing field name, such as billing_city. + * * @return boolean */ - public static function is_billing_address_required() { - $is_required = (bool) tutor_utils()->get_option( OptionKeys::IS_BILLING_ADDRESS_REQUIRED, true ); + public static function is_billing_field_required( string $field ) { + if ( in_array( $field, array( 'billing_first_name', 'billing_last_name', 'billing_email' ), true ) ) { + return true; + } - /** - * Filters whether the billing address field is required. - * - * @since 4.3.0 - * - * @param bool $is_required Whether the billing address is required. - */ - return (bool) apply_filters( 'tutor_is_billing_address_required', $is_required ); + $fields = self::get_configurable_billing_fields(); + if ( isset( $fields[ $field ] ) ) { + return (bool) tutor_utils()->get_option( $fields[ $field ], true ); + } + + return false; } /** - * Billing fields whose required state is controlled by a setting, - * mapped to their option key. + * Billing fields whose required state is controlled by a setting, mapped to their option key. * * @since 4.3.0 * @@ -594,37 +598,14 @@ public static function get_configurable_billing_fields() { ); } - /** - * Check whether a billing field is required. - * - * First name, last name and email are always required. The other fields - * follow their "Billing Address Configuration" setting. - * - * @since 4.3.0 - * - * @param string $field Billing field name, such as billing_city. - * - * @return boolean - */ - public static function is_billing_field_required( string $field ) { - $fields = self::get_configurable_billing_fields(); + public static function get_required_billing_fields() { + $required_fields = array(); + $configurable_billing_fields = array_keys( self::get_configurable_billing_fields() ); - if ( ! isset( $fields[ $field ] ) ) { - $is_required = in_array( $field, array( 'billing_first_name', 'billing_last_name', 'billing_email' ), true ); - } elseif ( 'billing_address' === $field ) { - $is_required = self::is_billing_address_required(); - } else { - $is_required = (bool) tutor_utils()->get_option( $fields[ $field ], true ); + foreach ( $configurable_billing_fields as $billing_field ) { + $required_fields[ $billing_field ] = self::is_billing_field_required( $billing_field ); } - /** - * Filters whether a billing field is required. - * - * @since 4.3.0 - * - * @param bool $is_required Whether the field is required. - * @param string $field Billing field name. - */ - return (bool) apply_filters( 'tutor_is_billing_fields_required', $is_required, $field ); + return $required_fields; } } diff --git a/models/BillingModel.php b/models/BillingModel.php index d024f16f14..c57d0c4b34 100644 --- a/models/BillingModel.php +++ b/models/BillingModel.php @@ -97,33 +97,32 @@ public function get_validation_rules() { * It is checked by validate_billing_location(). */ $rules = array( - 'billing_first_name' => 'required', - 'billing_last_name' => 'required', - 'billing_email' => 'required|email', + 'billing_first_name' => array( 'required' ), + 'billing_last_name' => array( 'required' ), + 'billing_email' => array( 'required', 'email' ), ); - foreach ( array( 'billing_phone', 'billing_zip_code', 'billing_address', 'billing_country', 'billing_city' ) as $field ) { - $rules[ $field ] = Settings::is_billing_field_required( $field ) ? 'required' : ''; + // The keys are field names, the values are option keys. + foreach ( array_keys( Settings::get_configurable_billing_fields() ) as $field ) { + if ( 'billing_state' === $field ) { + continue; + } + + // An optional field may be left out of the request, so check its format only when it is sent. + $rules[ $field ] = Settings::is_billing_field_required( $field ) ? array( 'required' ) : array( 'if_input' ); } - return $rules; - } + foreach ( self::get_field_formats() as $field => $format ) { + if ( isset( $rules[ $field ] ) ) { + $rules[ $field ][] = 'regex:/^(' . $format['pattern'] . ')?$/u'; + } + } - /** - * Get the billing fields that are required by the current settings. - * - * @since 4.3.0 - * - * @return string[] - */ - public function get_active_required_fields() { - return array_values( - array_filter( - $this->required_fields, - function ( $field ) { - return Settings::is_billing_field_required( $field ); - } - ) + return array_map( + function ( $field_rules ) { + return implode( '|', $field_rules ); + }, + $rules ); } @@ -142,20 +141,18 @@ function ( $field ) { */ public function validate_billing_location( string $country, string $state ): array { // An optional country may be left empty, but then a state makes no sense. - if ( '' === $country && ! Settings::is_billing_field_required( 'billing_country' ) ) { - return '' === $state ? array() : array( __( 'Invalid state', 'tutor' ) ); + if ( empty( $country ) && ! Settings::is_billing_field_required( 'billing_country' ) ) { + return empty( $state ) ? array() : array( __( 'Invalid Country for the given state', 'tutor' ) ); } $country_info = tutor_get_country_info_by_name( $country ); - if ( ! $country_info ) { return array( __( 'Invalid country', 'tutor' ) ); } $state_names = array_column( $country_info['states'] ?? array(), 'name' ); - // An optional state may be left empty. - if ( '' === $state && ! Settings::is_billing_field_required( 'billing_state' ) ) { + if ( empty( $state ) && ! Settings::is_billing_field_required( 'billing_state' ) ) { return array(); } @@ -338,7 +335,7 @@ public static function validate_field_formats( array $data ): array { foreach ( self::get_field_formats() as $field => $format ) { $value = trim( (string) ( $data[ $field ] ?? '' ) ); - if ( '' === $value ) { + if ( empty( $value ) ) { continue; } @@ -397,4 +394,22 @@ public static function get_field_formats(): array { */ return apply_filters( 'tutor_billing_field_formats', $formats ); } + + /** + * Get the billing fields that are required by the current settings. + * + * @since 4.3.0 + * + * @return string[] + */ + public function get_active_required_fields() { + return array_values( + array_filter( + $this->required_fields, + function ( $field ) { + return Settings::is_billing_field_required( $field ); + } + ) + ); + } } diff --git a/templates/ecommerce/billing-form-fields.php b/templates/ecommerce/billing-form-fields.php index 7816d598b1..61a2517a1c 100644 --- a/templates/ecommerce/billing-form-fields.php +++ b/templates/ecommerce/billing-form-fields.php @@ -27,14 +27,11 @@ use Tutor\Ecommerce\Settings; use TUTOR\Icon; -$show_close_button = $show_close_button ?? false; -$close_action = $close_action ?? 'editBilling = false'; -$country_options = $country_options ?? array(); -$initial_states = $initial_states ?? array(); -$required = array(); -foreach ( array( 'billing_phone', 'billing_country', 'billing_state', 'billing_city', 'billing_zip_code', 'billing_address' ) as $billing_field ) { - $required[ $billing_field ] = Settings::is_billing_field_required( $billing_field ); -} +$show_close_button = $show_close_button ?? false; +$close_action = $close_action ?? 'editBilling = false'; +$country_options = $country_options ?? array(); +$initial_states = $initial_states ?? array(); +$required = Settings::get_required_billing_fields(); ?> From ad0f6c131b4a9f56a432b049d0e49cc1b9eda75b Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Mon, 30 Nov 2026 14:01:36 +0600 Subject: [PATCH 12/13] code simplification --- ecommerce/Settings.php | 12 ++++-------- models/BillingModel.php | 19 +++++-------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/ecommerce/Settings.php b/ecommerce/Settings.php index d06fc2f0a3..1fc8e13673 100644 --- a/ecommerce/Settings.php +++ b/ecommerce/Settings.php @@ -599,13 +599,9 @@ public static function get_configurable_billing_fields() { } public static function get_required_billing_fields() { - $required_fields = array(); - $configurable_billing_fields = array_keys( self::get_configurable_billing_fields() ); - - foreach ( $configurable_billing_fields as $billing_field ) { - $required_fields[ $billing_field ] = self::is_billing_field_required( $billing_field ); - } - - return $required_fields; + return array_map( + fn( $option_key ) => (bool) tutor_utils()->get_option( $option_key, true ), + self::get_configurable_billing_fields() + ); } } diff --git a/models/BillingModel.php b/models/BillingModel.php index c57d0c4b34..a728ef45ef 100644 --- a/models/BillingModel.php +++ b/models/BillingModel.php @@ -102,28 +102,19 @@ public function get_validation_rules() { 'billing_email' => array( 'required', 'email' ), ); - // The keys are field names, the values are option keys. - foreach ( array_keys( Settings::get_configurable_billing_fields() ) as $field ) { - if ( 'billing_state' === $field ) { - continue; + foreach ( Settings::get_required_billing_fields() as $field => $is_required ) { + if ( 'billing_state' !== $field ) { + $rules[ $field ] = $is_required ? 'required' : 'if_input'; } - - // An optional field may be left out of the request, so check its format only when it is sent. - $rules[ $field ] = Settings::is_billing_field_required( $field ) ? array( 'required' ) : array( 'if_input' ); } foreach ( self::get_field_formats() as $field => $format ) { if ( isset( $rules[ $field ] ) ) { - $rules[ $field ][] = 'regex:/^(' . $format['pattern'] . ')?$/u'; + $rules[ $field ] .= '|regex:/^(' . $format['pattern'] . ')?$/u'; } } - return array_map( - function ( $field_rules ) { - return implode( '|', $field_rules ); - }, - $rules - ); + return $rules; } /** From d1aef7be1f633d96baffcd76c94bbc1a92ca2065 Mon Sep 17 00:00:00 2001 From: sanjana4khan Date: Mon, 30 Nov 2026 16:39:07 +0600 Subject: [PATCH 13/13] removed the array added in the previous commit --- models/BillingModel.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/BillingModel.php b/models/BillingModel.php index a728ef45ef..64eaea7b02 100644 --- a/models/BillingModel.php +++ b/models/BillingModel.php @@ -97,9 +97,9 @@ public function get_validation_rules() { * It is checked by validate_billing_location(). */ $rules = array( - 'billing_first_name' => array( 'required' ), - 'billing_last_name' => array( 'required' ), - 'billing_email' => array( 'required', 'email' ), + 'billing_first_name' => 'required', + 'billing_last_name' => 'required', + 'billing_email' => 'required|email', ); foreach ( Settings::get_required_billing_fields() as $field => $is_required ) {