Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
WillBrubaker / gist:f8a6bdd0a8755b5c2326
Last active August 29, 2015 14:24
Prevent capitalization of order item meta
/**
* By default, WooCommerce will capitalize order item meta labels
* in some cases this may be undesirable, use this snippet to
* un-do the capitalization
* @see wc function wc_attribute_label in includes/wc-attribute-functions.php
*/
add_filter( 'woocommerce_attribute_label', 'wooninja_attribute_label', 10, 2 );
function wooninja_attribute_label( $formatted_label, $original_label ) {
return $original_label;
@WillBrubaker
WillBrubaker / gist:deb149a1da3adeebe5af
Created July 7, 2015 13:28
Replace 'Free' from WooCommerce Booking price string
add_filter( 'woocommerce_get_price_html', 'wooninja_free_price_replace', 99, 2 );
function wooninja_free_price_replace( $price_html, $product ) {
if ( 'booking' == $product->product_type ) {
$price_html = str_replace( 'Free', 'MY REPLACEMENT', $price_html );
}
return $price_html;
}
@WillBrubaker
WillBrubaker / gist:47e0995d9c25f87f0123
Created July 1, 2015 18:30
Change WooCommerce 'Free' price
add_filter( 'woocommerce_free_price_html', 'wooninja_modify_free_price' );
function wooninja_modify_free_price( $price ) {
//modify MY FREE PRICE to fit your needs :)
return 'MY FREE PRICE';
}
@WillBrubaker
WillBrubaker / gist:7966dc6977bf68f652a8
Last active August 29, 2015 14:23
Dynamically adjust WooCommerce Subscriptions first synced payment date
/**
* I have a WooCommerce Subscription product set up to bill every 2nd month
* The product is also set up to synchronize payments to the 25th of each month
* and the products are shipped on the 1st of every 2nd month - the shipping
* schedule is fixed, i.e. shipments only go out on even numbered months
*
* How can I prevent my customers from being billed 5 weeks before their first box
* actually goes out?
*/
add_filter( 'woocommerce_subscriptions_synced_first_payment_date', 'wooninja_filter_first_payment_date', 10, 2 );
@WillBrubaker
WillBrubaker / gist:16aed85339534dc98bad
Created June 16, 2015 23:19
Force Resource Selection for WooCommerce Bookings Resources
add_filter( 'booking_form_fields', 'handsomebeardedguy_booking_form_fields' );
function handsomebeardedguy_booking_form_fields( $fields ) {
if ( isset( $fields['wc_bookings_field_resource'] ) ) {
$fields['wc_bookings_field_resource']['options'][0] = 'Make a selection...';
ksort( $fields['wc_bookings_field_resource']['options'] );
}
return $fields;
}
@WillBrubaker
WillBrubaker / gist:a44d620be7c0795b928c
Last active March 13, 2018 09:41
Add Quantity Input to the WooCommerce Shop Page (simple products only) Without A Template Override
add_action( 'woocommerce_before_shop_loop_item', 'beardedguy_add_quantity_input' );
function beardedguy_add_quantity_input() {
global $product;
$product_type = ( version_compare( WC_VERSION, '3.0', '<' ) ) ? $product->product_type : $product->get_type();
if ( 'simple' == $product_type ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 10 );
} else {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 10 );
@WillBrubaker
WillBrubaker / content-product.php
Last active August 29, 2015 14:23
Add Quantity Inputs to Simple Products on the WooCommerce Shop Page
<?php
/**
* The template for displaying product content within loops.
*
* Override this template by copying it to yourtheme/woocommerce/content-product.php
* Adapted from work originally authored by WooThemes
* @license [<http://fsf.org/>] [GPL 3]
* @version 1.6.4
*/
@WillBrubaker
WillBrubaker / css-snippet.css
Last active February 13, 2017 22:23
Allow Variable Selection on the Shop Page - WooCommerce
li.product-type-variable td {
float: left;
}
#main li.product input {
float: none;
}
@WillBrubaker
WillBrubaker / gist:509ea81f636132e03feb
Created June 12, 2015 12:02
Increase WooCommerce product prices by 20%
add_filter( 'woocommerce_get_price', 'wooninja_price_increase' );
function wooninja_price_increase( $price ) {
return $price + ( $price * .2 );
}
@WillBrubaker
WillBrubaker / gist:0e66c7a53cfcfecb16bd
Created June 10, 2015 13:17
Change WooCommerce Subscriptions "Change Payment Method" text
add_filter( 'woocommerce_change_payment_button_text', 'wooninja_change_payment_button_text' );
function wooninja_change_payment_button_text() {
return 'MY BUTTON TEXT';
}
add_filter( 'woocommerce_my_account_my_subscriptions_actions', 'wooninja_filter_subscriptions_actions', 99 );
function wooninja_filter_subscriptions_actions( $actions ) {
foreach ( $actions as $key => $value ) {