WooCommerce – remove payment method from emails

<?php // Do not include this if already open! /** * Code goes in theme functions.php. */ add_filter( 'woocommerce_get_order_item_totals', 'custom_woocommerce_get_order_item_totals' ); function custom_woocommerce_get_order_item_totals( $totals ) { unset( $totals['payment_method'] ); return $totals; } view raw gistfile1.txt hosted with ❤ by GitHub

WooCommerce – Hide shipping rates when free shipping is available.

<?php /** * Hide shipping rates when free shipping is available. * Updated to support WooCommerce 2.6 Shipping Zones. * * @param array $rates Array of rates found for the package. * @return array */ function my_hide_shipping_when_free_is_available( $rates ) { $free = array(); foreach ( $rates as $rate_id => $rate ) { if ( 'free_shipping'Continue reading “WooCommerce – Hide shipping rates when free shipping is available.”

WooCommerce – Add all upsells of a product to the cart via custom link

<?php // Do not include this if already open! /** * Code goes in theme functions.php. * Product must have upsells, and this works with simple products only. * Example link: yoursite.com?add-upsells-to-cart=X, X being your product ID. */ add_action( 'wp_loaded', 'bulk_upsell_add_to_cart_action', 20 ); function bulk_upsell_add_to_cart_action() { if ( ! empty( $_GET['add-upsells-to-cart'] ) ) { $product_idContinue reading “WooCommerce – Add all upsells of a product to the cart via custom link”

WooCommerce – enable free shipping only if product class is found in cart.

<?php // Do not include this if already open! /** * Code goes in theme functions.php. Free Shipping Method must be enabled. */ add_filter( 'woocommerce_shipping_free_shipping_is_available', 'free_shipping_based_on_cart_shipping_class' ); function free_shipping_based_on_cart_shipping_class( $is_available ) { /** * This example enables free shipping only when an item is found in the cart with a class named 'free_shipping' */ $cart_itemsContinue reading “WooCommerce – enable free shipping only if product class is found in cart.”

WooCommerce – Remove product data tabs and hook content in sequence instead

<?php // Do not include this if already open! /** * Remove existing tabs from single product pages. */ function remove_woocommerce_product_tabs( $tabs ) { unset( $tabs['description'] ); unset( $tabs['reviews'] ); unset( $tabs['additional_information'] ); return $tabs; } add_filter( 'woocommerce_product_tabs', 'remove_woocommerce_product_tabs', 98 ); /** * Hook in each tabs callback function after single content. */ add_action( 'woocommerce_after_single_product_summary',Continue reading “WooCommerce – Remove product data tabs and hook content in sequence instead”

Showing quantity inputs in WooCommerce loops

Here is a quick snippet showing how you can add quantity inputs to WooCommerce loops for simple products. This used to be only possible through template edits, but is now doable through filters because they are magic. <?php /** * Code should be placed in your theme functions.php file. */ add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2Continue reading “Showing quantity inputs in WooCommerce loops”

Github to WordPress.org deploy script

Today I polished, documented, and open sourced a bash script I’ve been using to do plugin deployments from Github to WordPress.org (plus I wanted an excuse to use the new WordPress.com desktop app which is awesome by the way). It’s based on code Barry Kooij sent me a while back. You can find it here: https://github.com/mikejolley/github-to-wordpress-deploy-script It handles Github tagging, removingContinue reading “Github to WordPress.org deploy script”

Debugging “unexpected token” in WooCommerce 2.4+

When the WooCommerce checkout is processed it requires that gateways return an array (which is then converted into JSON) telling the checkout whether or not it was successful. It’s been this way since v1. Here is a basic example from the PayPal gateway: return array( ‘result’ => ‘success’, ‘redirect’ => $paypal_request->get_request_url( $order, $this->testmode ) ); TheContinue reading “Debugging “unexpected token” in WooCommerce 2.4+”

So I spoke at WordCamp Netherlands…

Last week I was lucky enough to attend WordCamp Netherlands in Utrecht, followed by a small WC team meetup in Amsterdam. It was great to talk about work, plan for the future, and meet new and old friends. Rather than just attend the WordCamp I was actually a speaker. I presented a talk on user onboarding for plugins, usingContinue reading “So I spoke at WordCamp Netherlands…”