Created
June 23, 2026 15:04
-
-
Save xlplugins/79ef78f2602d5401b0c955fd95910cbb to your computer and use it in GitHub Desktop.
Weight Based Shipping fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: WFACP — make shipping Phone actually required (Weight Based Shipping fix) | |
| * | |
| * In plain terms: | |
| * The shipping "Phone" field is set to required, but customers can still | |
| * check out with it empty. This puts the requirement back. | |
| * | |
| * Why it broke: | |
| * In this checkout layout WooCommerce doesn't re-check shipping fields, and the | |
| * Weight Based Shipping plugin's "always show shipping" behaviour makes FunnelKit | |
| * forget the Phone field was required at the moment the order is placed. | |
| */ | |
| defined( 'ABSPATH' ) || exit; | |
| add_action( | |
| 'woocommerce_checkout_process', | |
| static function (): void { | |
| if ( ! class_exists( 'WFACP_Common' ) ) { | |
| return; | |
| } | |
| $id = WFACP_Common::get_id(); | |
| if ( empty( $id ) ) { | |
| return; // Not a FunnelKit checkout. | |
| } | |
| $fields = WFACP_Common::get_checkout_fields( $id ); | |
| if ( empty( $fields['shipping']['shipping_phone']['required'] ) || ! wc_string_to_bool( $fields['shipping']['shipping_phone']['required'] ) ) { | |
| return; | |
| } | |
| // Respect intl-tel-input hiding the field (e.g. ship-to-same collapses shipping). | |
| // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| $phone = isset( $_POST['wfacp_input_phone_field'] ) ? json_decode( stripslashes_deep( wp_unslash( $_POST['wfacp_input_phone_field'] ) ), true ) : array(); | |
| if ( isset( $phone['shipping']['hidden'] ) && 'yes' === $phone['shipping']['hidden'] ) { | |
| return; | |
| } | |
| // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| if ( ! isset( $_POST['shipping_phone'] ) || '' !== trim( wc_clean( wp_unslash( $_POST['shipping_phone'] ) ) ) ) { | |
| return; | |
| } | |
| $label = isset( $fields['shipping']['shipping_phone']['label'] ) ? $fields['shipping']['shipping_phone']['label'] : __( 'Phone', 'woocommerce' ); | |
| $message = sprintf( __( '%s is a required field.', 'woocommerce' ), '<strong>' . esc_html( $label ) . '</strong>' ); | |
| // Dedupe in case FunnelKit's own validator already added it. | |
| if ( ! ( function_exists( 'wc_has_notice' ) && wc_has_notice( $message, 'error' ) ) ) { | |
| wc_add_notice( $message, 'error' ); | |
| } | |
| }, | |
| 20 | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment