Woocommerce Edit order on admin dashboard - woocommerce

With Woocommerce, in Admin order edit pages, is there a way to move the post code on the second line?
Like in this screenshot:

The following code will allow you to change the display of the formatted billing and shipping address on Woocommerce admin single order (edit) pages for all countries:
add_filter( 'woocommerce_localisation_address_formats', 'admin_localisation_address_formats', 50, 1 );
function admin_localisation_address_formats( $address_formats ){
if( is_admin() ){
$address_formats = array();
$countries = array('default', 'AU', 'AT', 'BE', 'CA', 'CH', 'CL', 'CN', 'CZ',
'DE', 'EE', 'FI', 'DK', 'FR', 'HK', 'HU', 'IN', 'IS', 'IT', 'JP', 'TW', 'LI',
'NL', 'NZ', 'NO', 'PL', 'PT', 'SK', 'SI', 'ES', 'SE', 'TR', 'US', 'VN' );
foreach( $countries as $country_code ) {
$address_formats[$country_code] = "{company}\n{name}\n{address_1} {address_2} {postcode}\n{city} {state}\n{country}";
}
}
return $address_formats;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.

Related

Add ACF fields to taxonomy by submitting post

Lets say i have products based on woocommerce, and I want some specific functionality.
For example: inside product I created two ACF input fields:
Manufacter
Model
Then i have taxonomy named - "klb_make"
There must add Manufacter and Model values: Manufactur -> parent, Model -> child
Parent(some manufacter)
Child (some model)
Parent2(some manufacter2)
Child2(some modal2)
and so on..
i have tryed some code
$get_posts = new WP_Query;
add_action( 'init', function() {
$post_id = $get_posts;
$field_id = 'klb_make_type';
$value = 'My custom value';
rwmb_set_meta( $post_id, $field_id, $value );
}, 99 );`
or:
add_action( 'init', function() {
$post_id = $get_posts;
$field_id = 'klb_make_type';
$value = [
[
'parent' => 'Manufacter',
'child' => 'model',
],
[
'parent' => 'Manufacter2',
'child' => 'model2',
],
];
rwmb_set_meta( $post_id, $field_id, $value );
}, 99 );`
But didin't worked

How to add phone number masking in woo commerce my account page in wordpress [duplicate]

This question already has an answer here:
Add a mobile phone field on My account > edit account in Woocommerce
(1 answer)
Closed 6 months ago.
I want to add phone number masking on my account page of Woocommerce in wordpress?
Add the below code snippet in your active theme's functions.php file -
// Add field in Account Details
function wc_add_field_edit_account_form() {
woocommerce_form_field(
'user_phone_number',
array(
'type' => 'tel',
'required' => true, // for false do not need this `woocommerce_save_account_details_required_fields` callback
'label' => __( 'Phone Number', 'yourtextdomain' ),
),
get_user_meta( get_current_user_id(), 'user_phone_number', true )
);
}
add_action( 'woocommerce_edit_account_form', 'wc_add_field_edit_account_form' );
// Save field data
function wc_save_account_details( $user_id ) {
update_user_meta( $user_id, 'user_phone_number', wc_clean( $_POST[ 'user_phone_number' ] ) );
}
add_action( 'woocommerce_save_account_details', 'wc_save_account_details' );
// Add field required
function wc_add_account_details_required_fields( $required_fields ){
$required_fields[ 'user_phone_number' ] = __( 'Phone Number', 'yourtextdomain' );
return $required_fields;
}
add_filter( 'woocommerce_save_account_details_required_fields', 'wc_add_account_details_required_fields' );

Woocommerc rename field name in admin Customer billing address

How to rename of label "Phone" in admin area of Customer billing address?
You need to use woocommerce_customer_meta_fields filter.
add_filter( 'woocommerce_customer_meta_fields', 'filter_add_customer_meta_fields', 10, 1 );
function filter_add_customer_meta_fields( $args ) {
$args['billing']['fields']['billing_phone'] = array(
'label' => __( 'My custom text', 'woocommerce' ),
);
return $args;
}

billing field order in checkout page Woocommerce 4

in Woocommerce 4.2.0, in the checkout page, when I choose Spain, the "state" field is after the zipcode and the city fields:
but when I choose Ukraine, the the "state" field is after the city field and the zipcode field is after the state field:
Can you help me making the right order (as for Spain) for all countries with a "state" ?
I added this in functions.php, but Ukraine fields order is still wild:
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields', 90, 1 );
function custom_override_checkout_fields( $fields ) {
$fields['account']['account_username']['placeholder'] = __( 'Username or email*', 'woocommerce' );
$fields['account']['account_password']['placeholder'] = __( 'Password*', 'woocommerce' );
$fields['account']['account_password-2']['placeholder'] = __( 'Repeat password*', 'woocommerce' );
//set order of billing fields
$order = array(
"billing_first_name",
"billing_last_name",
"billing_company",
"billing_address_1",
"billing_address_2",
"billing_postcode",
"billing_city",
"billing_state",
"billing_country",
"billing_email",
"billing_phone"
);
foreach($order as $field)
{
$ordered_fields[$field] = $fields["billing"][$field];
}
$fields["billing"] = $ordered_fields;

Strict to 1 country only in checkout page with wordpress and woocommerce

I am using wordpress and woocommerce. In checkout page, how do I restrict to only 1 country only? Say Australia.
Hello you can restrict to only one country by plugin settings
you can find in Woocommerce->Settings-> Genral tab
Just override the class by hook,
function woo_override_checkout_fields_billing( $fields ) {
$fields['billing']['billing_country'] = array(
'type' => 'select',
'label' => __('My New Country List', 'woocommerce'),
'options' => array('AU' => 'Australia')
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'woo_override_checkout_fields_billing' );
function woo_override_checkout_fields_shipping( $fields ) {
$fields['shipping']['shipping_country'] = array(
'type' => 'select',
'label' => __('My New Country List', 'woocommerce'),
'options' => array('AU' => 'Australia')
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'woo_override_checkout_fields_shipping' );
This will help you to show only 1 country in dropdown. Add this code to functions.php in theme.
Also maybe you want to sell to several countries but also you want to show ONLY the country where the user is connecting from (geolocated from IP address). Thus, in this way, a french user will only see France in the country dropdown, an australian user will only see Australia in the country dropdown and so on... Here is the code:
/**
* #param array $countries
* #return array
*/
function custom_update_allowed_countries( $countries ) {
// Only on frontend
if( is_admin() ) return $countries;
if( class_exists( 'WC_Geolocation' ) ) {
$location = WC_Geolocation::geolocate_ip();
if ( isset( $location['country'] ) ) {
$countryCode = $location['country'];
} else {
// If there is no country, then return allowed countries
return $countries;
}
} else {
// If you can't geolocate user country by IP, then return allowed countries
return $countries;
}
// If everything went ok then I filter user country in the allowed countries array
$user_country_code_array = array( $countryCode );
$intersect_countries = array_intersect_key( $countries, array_flip( $user_country_code_array ) );
return $intersect_countries;
}
add_filter( 'woocommerce_countries_allowed_countries', 'custom_update_allowed_countries', 30, 1 );

Resources