I'm currently looking for a hook, to add a default billing title to the billing_title select to the WooCommerce checkout and change-address setting at the MyAccount page.
It should be something like Please select salutation and should be a required field. This field comes from the WooCommerce Germanized plugin and is a required field in Germany. Because of this there is no documentation about this (sadly).
This is my solution:
/**
* Add billing title default selection value
*/
add_filter( 'woocommerce_gzd_title_options', 'add_new_billing_title', 10, 1 );
function add_new_billing_title( $titles ) {
array_unshift( $titles, 'Bitte auswählen' );
return $titles;
}
I'm using array_unshift to add the default Please select value in German as first element in the select.
Related
My customers have to make a choice during the checkout to select if they are vat exempted or not. i use custom fields. I tried 3 solutions, all worked well:
Change items tax rate in WooCommerce checkout based on radio buttons
Add Tax Exempt form on checkout in woocommerce
and the best for me:
`
add_action( 'woocommerce_checkout_update_order_review', 'bbloomer_taxexempt_checkout_based_on_zip' );
function bbloomer_taxexempt_checkout_based_on_zip( $post_data ) {
WC()->customer->set_is_vat_exempt( false );
parse_str( $post_data, $output );
if ( $output['fsbdd_check_exotva'] === 'OUI' ) WC()->customer->set_is_vat_exempt( true );
}
`
But I can't change this setting in the woocommerce order admin page. if the customer was wrong or I need to edit the order manually I would like the VAT to change depending on this custom field.
I can manage the custom field with a metabox in the order backend (from metabox.io plugin). But there is no effect on the VAT. i would like the cart to be recalculate (recalculate button) once I have changed and saved the custom field value.
I have a custom field in ACF where I want to add a fixed fee to woocommerce checkout if the user select Office 1 and 00:00 - 07:00.
How can I make this work?
You can do this in this way.
add_action('woocommerce_cart_calculate_fees', 'packing_fee');
function packing_fee() {
global $woocommerce;
// Check your condition if true, add fee
$woocommerce->cart->add_fee('Fee Name', AMOUNT);
}
I'm using WooCommerce and Elementor Pro. Is there any way to add specific product attributes (e.g. gross and net weight) below the Add to cart button?
It seems like an obvious thing but I haven't found options or snippets for it.
First you add attributes to product. Then you use this snippet in functions.php:
// maybe remove tab with attributes
add_filter( 'woocommerce_product_tabs', 'remove_info', 100, 1 );
function remove_info( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
// show attributes
add_action( 'woocommerce_single_product_summary', 'summary_attributes', 35 );
function summary_attributes() {
global $product;
if ( $product->has_attributes() ) {
wc_display_product_attributes( $product );
}
}
Setting Up WooCommerce Attributes
go to Products > Attributes
Add the attribute name
Slug will automatically be created, and we can leave the rest of these options untouched.
Click “Add attribute” button and your attribute will be added.
Configure The Attributes
After creating attribute, now we can add different variation on your product. Click on the Configure Terms option.
Enter the variation
Add some short description
Click on the add new tab
To understand it in a better way you can follow this tutorial
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.
I used this tutorial to build my woocommerce custome field :
Woocommerce custom field variation
I just picked up the number field :
My code on pastbin
When using this code the field is shown on the admin screen, inside product variation section, and when i fill it with number it works but when i update it twice or more the field not updated, it always keep old value.
Anyone can help please?
Thank you
Here is your code:
add_action('woocommerce_save_product_variation', 'save_variable_fields', 10, 2);
function save_variable_fields($variation_id, $i)
{
$variable_number_field = $_POST['_number_field'];
update_post_meta( $variation_id, '_number_field', wc_clean( $variable_number_field[ $i ] ) );
}
My current woocommerce is 2.3.8