How to Add a 5% Surcharge to Your WooCommerce Cart / Checkout

* This is post #1 of 31 in the challenge “31 Ways to Customize WooCommerce”

This snippet mostly explained how you can add a 5% surcharge to WooCommerce cart / checkout based on conditions.

Option 2 (Add 5% surcharge for all) :

add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge_all' );

function woocommerce_custom_surcharge_all() {
  global $woocommerce;

  if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    return;

  $percentage = 0.05; //change this value for surcharge percentage
  $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;

  $woocommerce->cart->add_fee( 'Surcharge (5%)', $surcharge, true, 'standard' );
}

Continue reading

WooCommerce Product Badge

WooCommerce Product Badge

WooCommerce Product Badge” – A free WooCommerce plugin that let you display ‘New’, ‘Sale’ (Save %) and ‘Featured’ badge at shop and product page.

In WooCommerce Sidebar Menu, there will be a new submenu link called ‘Product Badge’ where you can:

  • Enabled / Disabled the plugin
  • Show “New” Badge
  • New Product with How Many Days?
  • Show “Sale” Badge
  • Show “Featured” Badge
WooCommerce > Product Badge Option Page

WooCommerce > Product Badge Option Page

Continue reading

How to Add Learn More Button to Shop Page

Today i would like to show you how to change “Add to cart” button text at WooCommerce shop or category page. Sometimes we need to add “Learn More” button at each product so that more people will click this button and redirect to product page, and we just need to use below code to update existing “Add to cart” text or just add a new button for each product.

You need to add below code into your theme functions.php file. (Check this guideline to add code into theme functions.php)
Continue reading

How to Add Code into WordPress Theme Functions.php

Sometimes you need to modify or update WooCommerce settings by using filter or action hook. But if you are totally newbie, do refer content below to get better understanding on how to do that.

Adter you login successfully to WordPress Admin, you can see “Appearance” sidebar menu on your left. Mouse over that and click “Editor” link. It will show “Edit Themes” page, default will be your current theme.

On your right sidebar got a list of files, do click “Theme Functions (functions.php)” link. You will see the file content, do paste below code before symbol ‘?>’ at the bottom.

For example:

add_filter('loop_shop_columns', 'custom_loop_columns');
if (!function_exists('custom_loop_columns')) {
	function custom_loop_columns() {
		return 3; //Display 3 products per row
	}
}

How to Add Payment Type to WooCommerce Admin New Email

WooCommerce will be sending out email notification to admin for any new order with completed status. Anyway, sometimes we need to know what is the chosen payment type for each order through email.

I will share the snippet below so that you can use to add payment type information to new order email for admin.

add_action( 'woocommerce_email_after_order_table', 'admin_new_order_email_payment_type', 15, 2 );

function admin_new_order_email_payment_type( $order, $is_admin_email ) {
  if ( $is_admin_email ) {
    echo '<p><strong>Payment Type:</strong> ' . $order->payment_method_title . '</p>';
  }
}

You can add those code into your theme functions.php.

Hope this will help anyone who need this.