'woocommerce local pickup plus - customer can validate checkout without choosing pickup location

I'm using Local Pickup Plus for woocommerce on my website because I want multiple pickup locations (pickup is the only choice for customer).

The plugin is working, except customer can validate checkout without choosing on scrolling menu the pickup location and date, it's not a required field.

I find in checkout.php file a function about error messages if pickup location has not been chosen, but it's not working on my website:

`public function validate_checkout( $posted_data ) {

    $local_pickup_method = wc_local_pickup_plus_shipping_method();
    $shipping_methods    = isset( $posted_data['shipping_method'] ) ? (array) $posted_data['shipping_method'] : [];
    $exception_message   = '';

    // check if there are any packages meant for local pickup
    if ( $local_pickup_packages = ! empty( $shipping_methods ) ? array_keys( $shipping_methods, $local_pickup_method->get_method_id() ) : null ) {

        $pickup_location_ids = isset( $_POST['_shipping_method_pickup_location_id'] ) ? $_POST['_shipping_method_pickup_location_id'] : [];
        $pickup_dates        = isset( $_POST['_shipping_method_pickup_date'] )        ? $_POST['_shipping_method_pickup_date']        : [];
        $appointment_offsets = Framework\SV_WC_Helper::get_posted_value( '_shipping_method_pickup_appointment_offset', [] );

        foreach ( $local_pickup_packages as $package_id ) {

            $error_messages = [];

            // a pickup location has not been chosen:
            if ( empty( $pickup_location_ids[ $package_id ] ) ) {
                /* translators: Placeholder: %s - user assigned name for Local Pickup Plus shipping method */
                $error_messages['pickup_location_id'] = sprintf( __( 'Please select a pickup location if you intend to use %s as shipping method.', 'woocommerce-shipping-local-pickup-plus' ), $local_pickup_method->get_method_title() );
            }

            // a pickup date has not been set, but it's mandatory:
            if ( empty( $pickup_dates[ $package_id ] ) && 'required' === $local_pickup_method->pickup_appointments_mode() ) {
                /* translators: Placeholder: %s - user assigned name for Local Pickup Plus shipping method */
                $error_messages['pickup_date'] = sprintf( __( 'Please choose a date to schedule a pickup when using %s shipping method.', 'woocommerce-shipping-local-pickup-plus' ), $local_pickup_method->get_method_title() );
            }

            // the selected appointment time is no longer available:
            if ( ! empty( $pickup_location_ids[ $package_id ] ) && ! empty( $pickup_dates[ $package_id ] ) ) {

                $appointment_offset = ! empty( $appointment_offsets[ $package_id ] ) ? (int) $appointment_offsets[ $package_id ] : 0;

                try {

                    $pickup_location = wc_local_pickup_plus_get_pickup_location( (int) $pickup_location_ids[ $package_id ] );

                    $now        = new \DateTime();
                    $start_date = new \DateTime( date( 'Y-m-d H:i:s', strtotime( $pickup_dates[ $package_id ] ) + $appointment_offset ), $pickup_location->get_address()->get_timezone() );

                    $appointment_duration = $pickup_location->get_appointments()->get_appointment_duration( $start_date );
                    $end_date             = ( clone $start_date )->modify( sprintf( "+ %d seconds", $appointment_duration ) );

                    if ( ! wc_local_pickup_plus()->get_appointments_instance()->is_appointment_time_available( $now, $pickup_location, $appointment_duration, $start_date, $end_date ) ) {

                        // remove selected pickup date and time so that only available times are shown
                        $data_store = new Package_Pickup_Data( $package_id );

                        $data_store->set_pickup_data( array_merge( $data_store->get_pickup_data(), [
                            'pickup_date'        => '',
                            'appointment_offset' => ''
                        ] ) );

                        // force WooCommerce to refresh checkout totals and render the appointment field again
                        WC()->session->set( 'refresh_totals', true );

                        throw new Framework\SV_WC_Plugin_Exception( 'Appointment time not available' );
                    }

                } catch ( \Exception $e ) {

                    $error_messages['pickup_time'] = __( 'Oops! That appointment time is no longer available. Please select a new appointment.', 'woocommerce-shipping-local-pickup-plus' );
                }
            }

`

I tried to disable all others plugins, nothing change.

Is there any way to fix this issue?

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source