• Resolved aribot

    (@aribot)


    Hi!
    the mandatory field “state” in checkout page didn’t work.

    • I added the code to the child Theme.
      https://prnt.sc/1qcyexg
    • I turn off all plugins, except woo commerce.
      https://prnt.sc/1qcbwxz
    • I switch to Twenty twenty-one theme.
      https://prnt.sc/1qcc058
    • But the field remains optional. Any reason why?

      In the last website (made 3 months ago) with the same theme and same plugins the code works. Maybe the cause is the new update of woo commerce?
      Thanks for your support,
      Ari

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    Have you added any other custom code? State is a required field by default, so in your case, something unique to your site (theme, plugins, custom coding..) is making the state field optional. If you’ve already switched to a default theme and deactivated all plugins except for WooCommerce, please also check if there is any other custom code that’s preventing the default functionality.

    Thread Starter aribot

    (@aribot)

    Hello Maykato,
    thank you for your support.
    There is other custome code for the cart page. I deleted but the problem remains.
    This is the code of the file functions.php

    <?php
    /**
     * Theme functions and definitions
     *
     * @package HelloElementorChild
     */
    
    /**
     * Load child theme css and optional scripts
     *
     * @return void
     */
    function hello_elementor_child_enqueue_scripts() {
    	wp_enqueue_style(
    		'hello-elementor-child-style',
    		get_stylesheet_directory_uri() . '/style.css',
    		[
    			'hello-elementor-theme-style',
    		],
    		'1.0.0'
    	);
    }
    add_action( 'wp_enqueue_scripts', 'hello_elementor_child_enqueue_scripts', 20 );
    /** Impostare un ordine minimo prima del pagamento **/
    add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
    add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
     
    function wc_minimum_order_amount() {
        // Set this variable to specify a minimum order value
        $minimum = 30;
    
        if ( WC()->cart->total < $minimum ) {
    
            if( is_cart() ) {
    
                wc_print_notice( 
                    sprintf( 'Attuale ordine di %s — Devi effettuare un ordine minimo di %s per poter procedere con il pagamento ' , 
                        wc_price( WC()->cart->total ), 
                        wc_price( $minimum )
                    ), 'error' 
                );
    
            } else {
    
                wc_add_notice( 
                    sprintf( 'Attuale ordine di %s — Devi effettuare un ordine minimo di %s per poter procedere con il pagamento ' , 
                        wc_price( WC()->cart->total ), 
                        wc_price( $minimum )
                    ), 'error' 
                );
    
            }
        }
    }
    add_filter( 'woocommerce_billing_fields', 'woo_filter_state_billing', 10, 1 );
    add_filter( 'woocommerce_shipping_fields', 'woo_filter_state_shipping', 10, 1 );
    function woo_filter_state_billing( $address_fields ) {
      $address_fields['billing_state']['required'] = true;
        return $address_fields;
    }
    function woo_filter_state_shipping( $address_fields ) {
        $address_fields['shipping_state']['required'] = true;
        return $address_fields;
    }
    Thread Starter aribot

    (@aribot)

    I don’t like use plug-in for this little things… But I solved with this https://www.ads-software.com/plugins/woocommerce-checkout-manager/

    • This reply was modified 3 years, 3 months ago by aribot.
    Mirko P.

    (@rainfallnixfig)

    Hi @aribot,

    Great to hear that you could solve it using that plugin. Thanks for letting us know!

    If you have more questions please feel free to open a new topic.

    Cheers.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Checkout page and field mandatory’ is closed to new replies.