Skip to content

Instantly share code, notes, and snippets.

View jackgregory's full-sized avatar

Jack Gregory jackgregory

View GitHub Profile
@jackgregory
jackgregory / functions.php
Last active August 29, 2015 14:01
WooCommerce - Add additional taxonomies to product related posts
add_filter( 'woocommerce_product_related_posts_query', 'product_related_posts_query' );
function product_related_posts_query( $query ) {
global $product, $wpdb;
if ( is_object( $product ) ) {
$terms_array = array(0);
// get brands
$terms = wp_get_post_terms( $product->id, 'product_brand' );
@jackgregory
jackgregory / functions.php
Last active December 15, 2015 22:58
WooCommerce - Disable and add 'sold out' to a single WooCommerce product variation dropdown
add_action( 'woocommerce_before_add_to_cart_form', 'woocommerce_variations_sold_out_filter' );
function woocommerce_variations_sold_out_filter() {
// disable and add "sold out" to product variations
wc_enqueue_js( '
var product_variations = $( "form.variations_form" ).data( "product_variations" );
// dont disable with multiple drop-downs
if ( product_variations && $( "form.variations_form" ).find( "select" ).length === 1 ) {
var attribute_name = $( "form.variations_form" ).find( "select" ).attr( "name" );
$.each( product_variations, function( key, value ) {