Forumsvar skapade

Visar 1 svar (av 1 totalt)
  • Trådstartare Peter

    (@myamiko)

    Hej, perfekt, Nicolas blog är riktigt bra. Såg nu att functions.php redan har kollen men den fungerar inte längre efter uppdateringar av woocommerce. Ärvd site så jag har dålig koll på den tidigare kodningen 🙂

    // Remove billing-fields when order total = 0
    add_filter( 'woocommerce_checkout_fields', 'remove_checkout_fields_when_ordertotal_is_zero', 20 );
    
    function remove_checkout_fields_when_ordertotal_is_zero( $fields ) {
    	global $woocommerce;
    	// if the total is more than 0 then we still need the fields
    	if ( 0 != $woocommerce->cart->total ) {
    		return $fields;
    	}
    	// return the regular billing fields if we need shipping fields
    	if ( $woocommerce->cart->needs_shipping() ) {
    		return $fields;
    	}
      // we don't need the billing fields so empty all of them except the email
      unset($fields['billing']['billing_first_name']);
      unset($fields['billing']['billing_last_name']);
      unset($fields['billing']['billing_company']);
      unset($fields['billing']['billing_address_1']);
      unset($fields['billing']['billing_city']);
      unset($fields['billing']['billing_postcode']);
      unset($fields['billing']['billing_country']);
      unset($fields['billing']['billing_state']);
      unset($fields['billing']['billing_phone']);
    	return $fields;
    }
Visar 1 svar (av 1 totalt)