Skip to content

Instantly share code, notes, and snippets.

@nielslange
Last active July 4, 2017 11:19
Show Gist options
  • Save nielslange/a0d4adb70ddf2120b3cfa5a7d07ff02b to your computer and use it in GitHub Desktop.
Save nielslange/a0d4adb70ddf2120b3cfa5a7d07ff02b to your computer and use it in GitHub Desktop.
WooCommerce snippets

WooCommerce snippets

Frontend Snippets

Add a surcharge to cart and checkout – uses fees API

Customize the WooCommerce breadcrumb

Automatically Complete Orders (functions.php)

Add a message above the login / register form (functions.php)

Allow HTML in term (category, tag) descriptions (functions.php)

Change the default state and country on the checkout (functions.php)

Override loop template and show quantities next to add to cart buttons (functions.php)

Custom tracking code for the thanks page (functions.php)

Make address fields wider (functions.php)

Exclude products from a particular category on the shop page (functions.php)

Set a custom add to cart URL to redirect to (functions.php)

Custom sorting options (asc/desc) (functions.php)

Make price widget draggable on touch devices (functions.php)

Editing product data tabs (functions.php)

Hide sub-category product count in product archives (functions.php)

Remove product content based on category (functions.php)

General Snippets

Access WC variables (functions.php)

//* Get global WC object
global $woocommerce;

//* Access various WooCommerce cart variables, see also https://docs.woothemes.com/wc-apidocs/class-WC_Cart.html
$woocommerce->cart->get_cart_subtotal();
$woocommerce->cart->get_cart_tax();
$woocommerce->cart->get_cart_total();

//* Access various WooCommerce customer variables, see also @see https://docs.woothemes.com/wc-apidocs/class-WC_Customer.html
$woocommerce->customer->get_country();
$woocommerce->customer->get_default_country();
$woocommerce->customer->get_shipping_country();

Forward all WC email notifications (functions.php)

//* Forward all WC email notifications
add_filter( 'woocommerce_email_headers', 'nl_forward_wc_email_notifocations', 10, 2);
function nl_forward_wc_email_notifocations($headers, $object) {
    $headers   = array();
    $headers[] = 'Bcc: Niels Lange <[email protected]>';
    $headers[] = 'Content-Type: text/html';

    return $headers;
}

Theming Snippets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment