Clear checkout fields in woocommerce - woocommerce

I'm trying to remove the autoloaded user info in the various checkout fields but cannot seem to find any way to access the fields value. I've tried the following which clears formatting, removes, the field, etc. but nothing I can find shows how to remove just the value. Does anyone know how to access this?
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_first_name']['placeholder'] = '';
$fields['billing']['billing_last_name']['value'] = '';
unset($fields['billing']['billing_company']);
return $fields;
}

Register filter:
add_filter( 'woocommerce_checkout_get_value' , 'clear_checkout_fields' );
Add this function. All fields will be empty.
function clear_checkout_fields($input)
{
return '';
}

Related

Editing the woocommerce checkout page "order notes"

I want to change the woocommerce checkout page's 'order notes' text field to 'special notes'. But I couldn't find the exact location of this file. Where I can find this file in my localhost folder?
Here is the screenshot of the page:
In this situation direct don't try to edit in plugin files. instead of that try to search for hook.
Here is the code you can add it in function file. it will change text and place holder also
function md_custom_woocommerce_checkout_fields( $fields )
{
$fields['order']['order_comments']['placeholder'] = 'Special notes';
$fields['order']['order_comments']['label'] = 'Add your special note';
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'md_custom_woocommerce_checkout_fields' );
To achieve that you need to use the woocommerce_checkout_fields filter and set $fields['order']['order_comments']['label'] to the text you want.
Here is the code for it. You should add it to your theme's function.php file or plugin.
add_filter( 'woocommerce_checkout_fields', 'change_order_note_label' );
/**
* Change Order Notes Label - WooCommerce
*
*/
function change_order_note_label( $fields ) {
$fields['order']['order_comments']['label'] = 'Special notes';
return $fields;
}
It worked for me
add_filter( 'woocommerce_checkout_fields' , 'theme_override_checkout_notes_fields' );
// Our hooked in function - $fields is passed via the filter!
function theme_override_checkout_notes_fields( $fields ) {
$fields['order']['order_comments']['placeholder'] = 'Add some order notes or a gift message here.';
$fields['order']['order_comments']['label'] = 'Order notes or gift message';
return $fields;
}

Removing the my account-dashboard and redirect to another endpoint like downloads

I don't want the customers to get linked to the myaccount-dashboard with the annoying Hello xy, from here you can blabla, when they click on "My Account".
Is there an endpoint for the my account dashboard? I didn't find it on the backend in woocommerce>Settings>Accounts...
What's working is: I set up a custom link under menu/navigation... called it "My Account" and set the link to /myaccount/downloads for example.
So, when customers are logged in and they click on My Account, they get redirected to Downloads.
I'm wondering, is there another way to get rid of the dashboard?
Or a redirect solution? Thanks.
Remove it using below function. change downloads to your requirement.
function custom_my_account_menu_items( $items ) {
unset($items['downloads']);
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'custom_my_account_menu_items' );
Looking more closely it seems like there are a handful of ways to do this. Take a look at the my-account.php template. You could override this, but I found that if you remove the woocommerce_account_content hook, you get a deprecation notice and WooCommerce thinks you have an outdated template and adds the content anyway.
Looking at the template you will see two hooks. The side menu navigation is added to the woocommerce_account_navigation and the content is added to woocommerce_account_content function. You can remove the defaults from their hooks and add back just the downloads content.
function so_41983566_remove_account_dadshboard(){
remove_action( 'woocommerce_account_navigation', 'woocommerce_account_navigation' );
remove_action( 'woocommerce_account_content', 'woocommerce_account_content' );
add_action( 'woocommerce_account_content', 'so_41983566_download_content' );
}
add_action( 'woocommerce_account_navigation', 'so_41983566_remove_account_dadshboard', 1 );
function so_41983566_download_content(){
do_action( 'woocommerce_account_downloads_endpoint' );
}
Or woocommerce_account_content() and woocommerce_account_navigation() are both pluggable functions and you can just define new versions in your theme/plugin.
This link explains everything:
https://github.com/woocommerce/woocommerce/wiki/Customising-account-page-tabs
First you need to create an endpoint:
function my_custom_endpoints() {
add_rewrite_endpoint( 'my-custom-endpoint', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
function my_custom_query_vars( $vars ) {
$vars[] = 'my-custom-endpoint';
return $vars;
}
add_filter( 'query_vars', 'my_custom_query_vars', 0 );
Then create the menu item:
function my_custom_my_account_menu_items( $items ) {
$logout = $items['customer-logout'];
unset( $items['customer-logout'] );
$items['my-custom-endpoint'] = __( 'My Custom Endpoint', 'woocommerce' );
$items['customer-logout'] = $logout;
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'my_custom_my_account_menu_items' );
Add content to the endpoint
function my_custom_endpoint_content() {
echo '<p>Hello World!</p>';
}
add_action( 'woocommerce_account_my-custom-endpoint_endpoint', 'my_custom_endpoint_content' );

disable postcode validation in WooCommerce checkout page

Does anybody know how to disable the Postcode validation on the checkout page in WooCommerce?
I want to input 'text content' in "billing_postcode" field, but the shop says it's an invalid postcode.
Does anyone know how I can disable Postcode validation or allow text characters?
Just do this:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields', 99 );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_postcode']['validate']);
unset($fields['shipping']['shipping_postcode']['validate']);
return $fields;
}
You can put this pretty much anywhere, but preferably in a custom plugin or in your theme's functions.php
You could try this:
add_filter( 'woocommerce_default_address_fields', 'custom_override_address_fields', 999, 1 );
function custom_override_address_fields( $address_fields ) {
// set as not required
$address_fields['postcode']['required'] = false;
// remove validation
unset( $address_fields['postcode']['validate'] );
return $address_fields;
}

WooCommerce - disable postcode validation

Does anybody know how to disable the Postcode validation on the checkout page in WooCommerce?
My country is set up as Switzerland, but I want also people from Austria and Germany allow to order.
So when I enter a German Postcode with 5 digits (in Switzerland there are only 4), the shop says it's an invalid postcode. (but in the settings I allowed every country).
Any idea how to fix that?
Adding this code to the functions.php file should work:
function custom_override_default_address_fields( $address_fields )
{
unset( $address_fields['postcode'] );
return $address_fields;
}
EDIT:
// Hook into the checkout fields (shipping & billing)
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Hook into the default fields
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
function custom_override_checkout_fields( $fields )
{
unset( $fields['billing']['billing_postcode'] );
unset( $fields['shipping']['shipping_postcode'] );
return $fields;
}
function custom_override_default_address_fields( $address_fields )
{
unset( $address_fields['postcode'] );
return $address_fields;
}
ANOTHER EDIT:
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
function custom_override_default_address_fields( $address_fields )
{
$address_fields['postcode']['required'] = false;
return $address_fields;
}
So I didn't actually find a simple code solution for this one but I noticed that if I set
WooCommerce > Preferences > General > Geolocate address
it will work (if settings are set to "Sell to all countries", in my case)
This code only removes validation of address fields in my-account page, what you need:
add_filter( 'woocommerce_default_address_fields',
'custom_override_default_address_fields' );
function custom_override_default_address_fields($address_fields)
{
$address_fields['postcode']['validate'] = false;
return $address_fields;
}
for billing and shipping:
add_filter( 'woocommerce_checkout_fields' , 'remove_postcode_validation', 99 );
function remove_postcode_validation( $fields ) {
unset($fields['billing']['billing_postcode']['validate']);
unset($fields['shipping']['shipping_postcode']['validate']);
return $fields;
}
Also i think with removing "validate-required" class in wc-template-function.php, this feature will be deactivated (no test).
Sorry for bad English and hope this solutions solve your problem.
The previous answers don't seem to address the question! The postcode is still a required field, it's matter of whether other postcodes can be allowed that WooCommerce is saying is wrong.
For a checkout I'm building I've used this filter to allow any postcode to be considered valid regardless of country/postcode given.
add_filter( 'woocommerce_validate_postcode' , 'mycode_override_postcode_check', 99, 3 );
function mycode_override_postcode_check( $valid, $postcode, $country ) {
return true;
}
You can change that return true; for more complex code logic that reviews the postcode and country, this can help if your version of WooCommerce doesn't cover new postcode/zip code rules and you need them to be accepted.
Source: https://github.com/EloxZ/wordpresscrm/blob/main/wp-content/plugins/woocommerce/includes/class-wc-validation.php#L123

xprofile_allowed_tags not accepting unordered list

Im trying to get my Budypress site to work with wp_editor on profile fields. So far everything is ok but my tags are being striped.
I added the following:
add_filter( 'xprofile_allowed_tags', 'custom_xprofile_allowed_tags' );
function custom_xprofile_allowed_tags($tags){
$tags['li'] = array();
$tags['ul'] = array(
'type' => true
);
return $tags;
}
But it still saving my profile field without <ul><li>
I know the filter is working because if i add unset($tags['strong']); the strong tag is stripped.
Thanks for the help
My code was working fine i didn't realize that i also need to change filter for displaying the data.
So my code is :
function xprofile_with_html() {
//change allowed tags to use the same as posts when save
add_filter( 'xprofile_allowed_tags', 'custom_xprofile_allowed_tags',0 );
//remove wp_filter and add custom one when showing in edit field
remove_filter( 'bp_get_the_profile_field_edit_value', 'wp_filter_kses', 1 );
add_filter( 'bp_get_the_profile_field_edit_value', 'my_custom_profile_filter',0,3 );
}
add_action( 'bp_init', 'xprofile_with_html' );
function custom_xprofile_allowed_tags($tags){
global $allowedposttags;
return $allowedposttags;
}
function my_custom_profile_filter($data){
return xprofile_filter_kses($data);
}
With these i can use wp_editor for my xprofile fields

Resources