Add a custom checkbox in WooCommerce checkout which value shows in admin edit order

You can do it in 3 steps: Adding the custom checkbox field below the Payment Methods Saving the custom checkbox field when it’s checked in the order meta Displaying the custom checkbox field when it’s checked on the order edit page Here is that code: // Add custom checkout field: woocommerce_review_order_before_submit add_action( ‘woocommerce_review_order_before_submit’, ‘my_custom_checkout_field’ ); … Read more

Show hide custom Woocommerce checkout field based on selected payment method

The following code will hide billing_options custom optional checkout field when the selected payment method is Cash on delivery (“cod”): // Conditional Show hide checkout fields based on chosen payment methods add_action( ‘wp_footer’, ‘conditionally_show_hide_billing_custom_field’ ); function conditionally_show_hide_billing_custom_field(){ // Only on checkout page if ( is_checkout() && ! is_wc_endpoint_url() ) : ?> <script> jQuery(function($){ var a=”input[name=”payment_method”]”, … Read more

Changing WooCommerce cart item names

The woocommerce_order_item_name filter hook is a front-end hook and is located in: 1) WooCommerce templates: emails/plain/email-order-items.php templates/order/order-details-item.php templates/checkout/form-pay.php templates/emails/email-order-items.php 2)WooCommerce Core file: includes/class-wc-structured-data.php Each of them has $item_name common first argument, and different for the other arguments. See Here for more details… You have 2 arguments set in your function (the second one is not … Read more

Remove attribute values from product variation title and show them on separate rows

UPDATED 1) Since WooCommerce 3+, to remove attribute values from Product variation title and to display them in a separate row will need to use this 2 dedicated simple hooks (in checkout page). Removing attribute values from Product variation title: add_filter( ‘woocommerce_product_variation_title_include_attributes’, ‘variation_title_not_include_attributes’ ); function variation_title_not_include_attributes( $boolean ){ if ( ! is_cart() ) $boolean = … Read more

Customize addresses fields on WooCommerce My account and Checkout

The hook woocommerce_checkout_fields only allow customizations on checkout page and will not affect the My account “Addresses” section fields. The following will affect both My account “Addresses” section fields and checkout fields, allowing to make billing and shipping fields customized also on the related my account section. 1) For addresses fields (both billing and shipping) … Read more

How should I change the woocommerce_form_field HTML Structure?

To rewrite the output html from the woocommerce_form_field function there are 2 filter hooks available: Filter by type: here we can specify the $args[‘type’] like text, password, datetime, select, radio, etc… /** * Filter by type. */ $field = apply_filters( ‘woocommerce_form_field_’ . $args[‘type’], $field, $key, $args, $value ); General filter on form fields: a general … Read more

WooCommerce: Set country by default in checkout page

Update (Since WooCommerce 3) This are the woocommerce hooks and code to be used for this purpose for country (and optionally state): add_filter( ‘default_checkout_billing_country’, ‘change_default_checkout_country_and_state’ ); add_filter( ‘default_checkout_shipping_country’, ‘change_default_checkout_country_and_state’ ); add_filter( ‘default_checkout_billing_state’, ‘change_default_checkout_country_and_state’ ); add_filter( ‘default_checkout_shipping_state’, ‘change_default_checkout_country_and_state’ ); function change_default_checkout_country_and_state( $default ) { return null; } Or even shorter: add_filter( ‘default_checkout_billing_country’, ‘__return_null’ ); add_filter( ‘default_checkout_shipping_country’, … Read more

Add fee based on specific payment methods in WooCommerce

2021 UPDATE Note: All payment methods are only available on Checkout page. The following code will add conditionally a specific fee based on the chosen payment method: // Add a custom fee (fixed or based cart subtotal percentage) by payment add_action( ‘woocommerce_cart_calculate_fees’, ‘custom_handling_fee’ ); function custom_handling_fee ( $cart ) { if ( is_admin() && ! … Read more