Home Forums WoodMart support forum Bug in the WoodMart Checkout Fields editor with the “country” dropdown field Reply To: Bug in the WoodMart Checkout Fields editor with the “country” dropdown field

#582009

Artem Temos
Keymaster

1. Try to edit the file wp-content\themes\woodmart\inc\integrations\woocommerce\modules\checkout-fields\class-frontend.php and find the following method update_checkout_fields (https://monosnap.com/file/hrrXZuVGBi2CcjmQ03hOZl8XtVTy9T)

2. Replace it with the following code

public function update_checkout_fields( $checkout_fields ) {
		if ( ! woodmart_get_opt( 'checkout_fields_enabled' ) || ! is_checkout() ) {
			return $checkout_fields;
		}

		$change_options = get_option( 'xts_checkout_fields_manager_options', array() );

		if ( empty( $change_options ) ) {
			return $checkout_fields;
		}

		foreach ( $change_options as $group_key => $checkout_groups_fields ) {
			if ( ! isset( $checkout_fields[ $group_key ] ) ) {
				continue;
			}

			foreach ( $checkout_groups_fields as $field_key => $checkout_field ) {
				if ( isset( $checkout_field['status'] ) && ! $checkout_field['status'] ) {
					unset( $checkout_fields[ $group_key ][ $field_key ] );

					continue;
				}

				if ( ! isset( $checkout_fields[ $group_key ][ $field_key ] ) ) {
					$checkout_fields[ $group_key ][ $field_key ] = $checkout_field;
					continue;
				}

				// Remove screen reader.
				if ( isset( $checkout_fields[ $group_key ][ $field_key ]['label_class'] ) && is_array( $checkout_fields[ $group_key ][ $field_key ]['label_class'] ) && in_array( 'screen-reader-text', $checkout_fields[ $group_key ][ $field_key ]['label_class'], true ) ) {
					unset( $checkout_fields[ $group_key ][ $field_key ]['label_class'][ array_search( 'screen-reader-text', $checkout_fields[ $group_key ][ $field_key ]['label_class'], true ) ] );
				}

				// Remove old position class before added new.
				$remove_classes    = array();
				$positions_classes = array(
					'form-row-first',
					'form-row-wide',
					'form-row-last',
				);

				foreach ( $positions_classes as $positions_class ) {
					$remove_classes[] = array_search( $positions_class, $checkout_fields[ $group_key ][ $field_key ]['class'], true );
				}

				$remove_classes = array_filter(
					array_unique( $remove_classes ),
					function ( $el ) {
						return $el || 0 === $el;
					}
				);

				if ( ! empty( $remove_classes ) ) {
					foreach ( $remove_classes as $id ) {
						unset( $checkout_fields[ $group_key ][ $field_key ]['class'][ $id ] );
					}
				}

				$checkout_fields[ $group_key ][ $field_key ] = $this->helper->recursive_parse_args( $checkout_field, $checkout_fields[ $group_key ][ $field_key ] );
			}
		}

		return $checkout_fields;
	}