I'm trying to remove some required billing fields if the checkout page based on a certain page template.
Everything in the code below works fine if I remove the if condition, but with the condition even though the fields are unset it still throws the required field error on submission. I also tried a different condition such as checking for a $_GET variable but that didn't work either, it is an option though.
function custom_override_checkout_fields( $fields ) {
if ( is_page_template( 'page-simple.php') ) {
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
unset($fields['order']['order_comments']);
return $fields;
} else {
return $fields;
}
}
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
I've already ruled out a plugin or theme conflict by changing to twentysixteen and disabling all unnecessary plugins. I'm running the latest version of Woocommerce as of post. I'm running the One Page Checkout plugin to give me separate checkout pages, but ruled it out as the issue since this doesn't work with the regular checkout either when a condition is present.
Please let me know if I'm missing some information that would be helpful in troubleshooting this.
Related
I am stuck with trying to configure my website's checkout fields in woo commerce.It comes prefilled with values and doesnt get removed even after purging the cache.
https://shinujohn.com/checkout/ ...set as with the default shortcode
The country has 2 field boxes now...one is clickable drop down.
Server side caching is disabled.
The theme I'm using is Kallyas
I Have tried:-
Field editor : It does not even show the field ..say company name.and adding a new field is not reflected here.even if i add it to the billing or checkout fields
Adding code to functions.php
/returning woo commerce field as blank/
add_filter('woocommerce_checkout_get_value','__return_empty_string', 1, 1);
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
or
function custom_override_billing_fields( $fields ) {
unset($fields['billing_postcode']);
unset($fields['billing_state']);
unset($fields['billing_country']);
unset($fields['billing_address_1']);
return $fields;
}
neither work
3. issue persists with multiple browsers and unlogged users in different machines..
4. Within the theme's page editor... i can of course change front end ...but it doesnt reflect it after publishing.
I don't recommend you to use any extra plugin to edit the Woocommerce checkout fields. Here is the simple solution that you can easily customize the Woocommerce checkout fields.
add_filter( 'woocommerce_checkout_fields' , 'custom_override_billing_fields', 5);
function custom_override_billing_fields( $fields ) {
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_address_1']);
return $fields;
}
May this code helps you.
I am trying to customize my "Add new" order page.
I want to remove the "Add product(s)" line along with other lines on that row.
would love to have some explanation of how to find the relevant data for filtering the buttons out.
I have searched the forum and found that adding a similar filter might be the option.
// remove Order Notes from checkout field in Woocommerce
add_filter( 'woocommerce_checkout_fields' , 'alter_woocommerce_checkout_fields' );
function alter_woocommerce_checkout_fields( $fields ) {
unset($fields['order']['order_comments']);
return $fields;
}
I designed a WooCommerce template for a customer. Now he wants to remove prices and visitors only add what they want to the list. So there will be no payment method. s:
- I can't change plugin or database. All data must remain how they are.
- I need to remove prices from all over the site. where ever they are. Cart, wishlist, single page & etc.
- I need to change payment method to something like submit list.
- at the end after submit list page there must be a contact info page.
please help.
You can hook into wc_price and remove the prices there
function my_filter_wc_price( $price ){
return '';
}
add_filter( 'wc_price', 'my_filter_wc_price' );
Then you can hook into parse_query and redirect the checkout page to the contact page.
function my_parse_query(){
if( is_page( wc_get_page_id( 'checkout' ) ) ){
wp_redirect( '/contact' );
exit;
}
}
add_action( 'parse_query', 'my_parse_query' );
That will stop people from being able purchasing things. Just hiding the price with CSS will not. They will still be able to craft URL's to add to cart, and find the cart / checkout pages.
since I found no other way I decided to do it width CSS and translation.
I removed all prices by display:none;
and I translated all the strings which are about shop and price.
I am currently trying to add new custom emails to the woocommerce emails list.
I have followed the instructions from this link : https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
I use a custom action for this email (ch_deadline) which I trigger with this in my plugin:
add_action( 'ch_deadline_notification', array( $this, 'trigger' ) );
As I have seen in this post : WooCommerce - send custom email on custom order status change, I need to add it to the woocommerce email actions :
add_filter( 'woocommerce_email_actions', 'add_deadline_email_actions' ); // WC 2.3+
function add_deadline_email_actions( $email_actions ) {
$email_actions[] = 'ch_deadline';
return $email_actions;
}
In the front-end, it works well, it display my new email in the list.
Unfortunately the email has never been sent.
I have read a lot of post about this problem but none of the proposed solutions resolved the problem
I have even tried to add directly my action in $email_actions list in class-wc-emails.php
If you have any ideas, I'm more than interested !
Thanks !
Im running a web shop based on WP and WooCommerce. After the latest WC update some things changed on my checkout page and I'm looking for a way to trim the page a bit.
What I'm looking to do is to remove some of the unnecessary options shown to customers. I'm just not quite sure how do this :)?
What i want to hide/remove is:
(1) Since i only sell to Denmark
Land *
Danmark
(2) The second input box for address. Only the first is needed.
Adresse*
Apartment, suite etc.
(3) Additional information section - I dont need to have this either.
YDERLIGERE INFORMATION
Ordre Bemærkninger
I really hope that someone out there will be able to answer this and help me out! :)
The website is www.motorcykelgrej.dk <- to access the checkout page you need to add something to the basket first.
Best regards
Michael
Add this to your theme functions.php:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_address_2']);
unset($fields['order']['order_comments']);
return $fields;
}
And this custom CSS code:
.checkout-group h3 {
display:none;
}