Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
WillBrubaker / gist:0fef5891ce92a551538f
Created June 9, 2015 17:05
Localize WooCommerce Bookings Date Format
/**
* See Documentation on Date/Time formatting here:
* https://codex.wordpress.org/Formatting_Date_and_Time
*/
add_filter( 'woocommerce_bookings_time_format', 'localize_bookings_time_format' );
function localize_bookings_time_format( $format ) {
return get_option( 'time_format', $format );
}
@WillBrubaker
WillBrubaker / gist:4d9f1cd122513e9eb0bc
Created June 3, 2015 03:37
Restrict WooCommerce order notes field to a number of characters
add_filter( 'woocommerce_checkout_fields', 'filter_checkout_fields' );
function filter_checkout_fields( $fields ) {
$fields['order']['order_comments']['maxlength'] = 200;
return $fields;
}
@WillBrubaker
WillBrubaker / gist:448c55887c7a92624b4f
Created June 1, 2015 02:40
Allow WooCommerce users to access their profile and the WordPress dashboard
add_filter( 'woocommerce_prevent_admin_access', '__return_false' );
@WillBrubaker
WillBrubaker / gist:dc691d9df80aa63fc9ac
Created May 28, 2015 10:22
Change the WooCommerce Bookings "Persons" label to something else
add_filter( 'booking_form_fields', 'wooninja_booking_form_fields' );
function wooninja_booking_form_fields( $fields ) {
$fields['wc_bookings_field_persons']['label'] = 'SOMETHING ELSE';
return $fields;
}
@WillBrubaker
WillBrubaker / gist:353709b64fa800a33bae
Created May 25, 2015 13:34
Changes 'Product Description' text in WooCommerce tabs
add_filter( 'woocommerce_product_description_heading', 'wooninja_product_description_heading', 10, 0 );
function wooninja_product_description_heading() {
return 'Project Description';
}
@WillBrubaker
WillBrubaker / gist:305b73925005e26968b7
Created May 22, 2015 15:13
Add Mongolian currency and symbol to WooCommerce
add_filter( 'woocommerce_currencies', 'wooninja_add_currencies' );
function wooninja_add_currencies( $currencies ) {
$currencies['MNT'] = 'Mongolian Tughrik';
return $currencies;
}
add_filter( 'woocommerce_currency_symbol', 'wooninja_currency_symbol', 10, 2 );
function wooninja_currency_symbol( $currency_symbol, $currency ) {
@WillBrubaker
WillBrubaker / gist:a6575ad4147efb516b78
Created May 22, 2015 11:58
WooCommerce "Ship to different address" default to "no/unchecked"
add_filter( 'woocommerce_ship_to_different_address_checked', '__return_zero' );
@WillBrubaker
WillBrubaker / gist:49ccb5365a8632b8af8e
Created May 20, 2015 20:47
Remove the postcode field from the WooCommerce shipping calculator
add_filter( 'woocommerce_shipping_calculator_enable_postcode', '__return_false' );
@WillBrubaker
WillBrubaker / gist:154cec18cd060246d9a8
Created May 19, 2015 13:58
Conditionally change 'read more' to 'book now' if a bookable product
add_filter( 'woocommerce_product_add_to_cart_text', 'wooninja_read_more_text', 10, 2 );
function wooninja_read_more_text( $text, $product ) {
if ( 'booking' == $product->product_type ) {
$text = 'Book Now';
}
return $text;
}
@WillBrubaker
WillBrubaker / gist:0ffdc0aed0c574b6c3a5
Last active March 8, 2018 22:55
Filters the default WooCommerce product category shortcode to only include items on sale
add_filter( 'woocommerce_shortcode_products_query', 'wooninja_only_sale_items', 10, 2 );
function wooninja_only_sale_items( $args, $atts ) {
if ( $atts['category'] ) {
$product_ids_on_sale = wc_get_product_ids_on_sale();
$args['post__in'] = array_merge( array( 0 ), $product_ids_on_sale );
}
return $args;
}