Skip to content

Instantly share code, notes, and snippets.

View mikejolley's full-sized avatar

Mike Jolley mikejolley

View GitHub Profile
@mikejolley
mikejolley / gist:1622409
Last active November 25, 2018 13:00
WooCommerce - Set a custom add to cart URL to redirect to
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );
function custom_add_to_cart_redirect() {
/**
* Replace with the url of your choosing
* e.g. return 'http://www.yourshop.com/'
*/
return get_permalink( get_option('woocommerce_checkout_page_id') );
}
@mikejolley
mikejolley / gist:1622644
Created January 16, 2012 19:59
WooCommerce - Custom sorting options (asc/desc)
/**
* This code should be added to functions.php of your theme
**/
add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args');
function custom_woocommerce_get_catalog_ordering_args( $args ) {
if (isset($_SESSION['orderby'])) {
switch ($_SESSION['orderby']) :
case 'date_asc' :
$args['orderby'] = 'date';
@mikejolley
mikejolley / gist:1717863
Created February 1, 2012 16:27
WooCommmerce - Custom coupon logic
/*
* This code goes into your theme's functions.php
*/
add_filter( 'woocommerce_coupon_is_valid', 'custom_woocommerce_coupon_is_valid', 1, 2 );
function custom_woocommerce_coupon_is_valid( $valid, $coupon ) {
if ($coupon=='YOURCOUPONCODE') {
$min_quantity = 12;
@mikejolley
mikejolley / gist:1733834
Created February 3, 2012 23:53
WooCommerce - Make address fields wider
add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields');
function custom_woocommerce_billing_fields( $fields ) {
$fields['billing_address_1']['class'] = array( 'form-row-wide' );
$fields['billing_address_2']['class'] = array( 'form-row-wide' );
return $fields;
}
@mikejolley
mikejolley / gist:1751128
Last active November 7, 2019 13:24
WooCommerce - Hide loop buttons for out of stock items
/*
* Override via functions.php
**/
if (!function_exists('woocommerce_template_loop_add_to_cart')) {
function woocommerce_template_loop_add_to_cart() {
global $product;
if ( ! $product->is_in_stock() || ! $product->is_purchasable() ) return;
woocommerce_get_template('loop/add-to-cart.php');
}
}
@mikejolley
mikejolley / gist:1751818
Created February 6, 2012 12:15
WooCommerce - WooSEO for the shop page/custom post type archive
add_filter('woo_title', 'woocommerce_shop_page_title');
function woocommerce_shop_page_title( $title ) {
if ( is_post_type_archive('product') ) {
$title = get_post_meta(woocommerce_get_page_id('shop'), 'seo_title', true);
}
return $title;
}
@mikejolley
mikejolley / gist:1800395
Created February 11, 2012 15:01
WooCommerce - Change order notes placeholder
add_filter('woocommerce_checkout_fields', 'custom_woocommerce_checkout_fields');
function custom_woocommerce_checkout_fields( $fields ) {
$fields['order']['order_comments']['placeholder'] = 'Your custom placeholder';
return $fields;
}
@mikejolley
mikejolley / functions.php
Last active April 23, 2018 13:31
WooCommerce - Custom tracking code
add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
function my_custom_tracking( $order_id ) {
// Lets grab the order
$order = wc_get_order( $order_id );
/**
* Put your tracking code here
* You can get the order total etc e.g. $order->get_total();
@mikejolley
mikejolley / gist:1860056
Created February 18, 2012 16:27
WooCommerce - Override billing fields
add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
function custom_woocommerce_billing_fields( $fields ) {
// Over-ride a single label
$fields['billing_first_name']['label'] = 'Your label';
// Over-ride a single required value
$fields['billing_first_name']['required'] = false;
@mikejolley
mikejolley / gist:1926284
Last active June 8, 2020 17:24
WooCommerce - Change WooCommerce email subject lines
/*
* goes in theme functions.php or a custom plugin
*
* Subject filters:
* woocommerce_email_subject_new_order
* woocommerce_email_subject_customer_processing_order
* woocommerce_email_subject_customer_completed_order
* woocommerce_email_subject_customer_invoice
* woocommerce_email_subject_customer_note
* woocommerce_email_subject_low_stock