Im trying to set the shipping country automatically based on customer location.. any clues?
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
function change_default_checkout_country() {
return "AE";
}
Related
In Woocommerce: I found this code to set a custom country selected in the Country field of the Checkout Billing form, which works fine:
/**
* Change default_checkout_billing_country
*/
add_filter( 'default_checkout_billing_country', 'change_default_checkout_billing_country' );
function change_default_checkout_billing_country() {
return 'XX'; // country code
}
But this only affect the form. I need to set the geolocation for the whole site. I need this because I need the prices to be shown with/without taxes depending on the country.
I know that this is managed for woocommerce geolocation. But I need this for developer purposes.
Important: I need the filter to be fired on the 'init' and not in the checkout page.
Update: I tried with this, but not working:
/**
* Change default_checkout_country
*/
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
function change_default_checkout_country() {
return 'XX'; // country code
}
in the default order tracking page for wooocommerce there are two fields { ordreid and email }
.
I want to make email field unrequired
I tried with this code in function.php file but it wasn't successful :(
add_filter( 'woocommerce-order-tracking', 'ts_unrequire_wc_email_field');
function ts_unrequire_wc_email_field( $fields ) {
$fields['order_email']['required'] = false;
return $fields;
}
any help will be useful .. and i hope that you are all safe during the breakout of covid-19 <3**
How do you change the woo-commerce checkout form for different shipping options? If they choose free shipping the checkout page displays shipping form. If they choose e-voucher the check out page displays a simpler form.
You can use the below code snippet to hide whichever fields you chose when the "e-voucher" shipping method is chosen. Simply put the following inside your functions file.
<?php
add_filter('woocommerce_checkout_fields', 'evoucher_remove_fields');
function evoucher_remove_fields($fields) {
$shipping_method ='evoucher:1'; // Change this to the value name of your shipping method
global $woocommerce;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ($chosen_shipping == $shipping_method) {
unset($fields['billing']['billing_address_1']); // Hides billing address line 1
unset($fields['billing']['billing_address_2']); // Hides billing address line 2
}
return $fields;
}
?>
Source
There is a good plugin for such purposes. Its free version includes conditional logic, e.g. change the form with the base on shipping option.
How to make woocommerce always show price including tax based on shop location and only in checkout would woocommerce show price depends on user country.
It is possible?
Thank you
A lot later, just in case someone else still needs it.
I don't know if you can show prices based on the shop location only before the checkout, but you can surely assign a default country to the user if they have never bought before.
If they are returning customers, it's right they see the taxes according to their country, if not so it's not a so bad idea to assign them as a default country the shop country.
Translated in code:
add_filter( 'default_checkout_billing_country',function( $country ){
if ( WC()->customer->get_is_paying_customer() ) {
return $country;
}
return wc_get_base_location()['country'];
} );
add_action('woocommerce_add_to_cart' ,function(){
if( !WC()->customer->get_is_paying_customer() ) {
$country = wc_get_base_location()['country'];
WC()->customer->set_billing_country( $country );
}
} );
how i can disable Check booking availability and send direct user to make payment in listify wordpress theme. now it send a confirm mail then user can make payment but i want it directly how can i do this any one help please
Use this in function.php
function manage_available_gateways( $gateways ) {
unset($gateways['wc-booking-gateway']);
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'manage_available_gateways' );