Skip to content

Instantly share code, notes, and snippets.

@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: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: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: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:21a245e0e0ee7e006202
Last active August 2, 2016 02:56
Change WooCommerce Booking Duration Label
add_filter( 'booking_form_fields', 'wooninja_booking_form_fields' );
function wooninja_booking_form_fields( $fields ) {
//Changes the text 'Day(s)' to 'Night(s)'
$fields['wc_bookings_field_duration']['after'] = str_replace( 'Day(s)', 'Night(s)', $fields['wc_bookings_field_duration']['after'] );
return $fields;
}
@WillBrubaker
WillBrubaker / gist:dbd3d21da0af6695f2de
Last active August 4, 2019 18:10
Change WooCommerce Bookings "Check Availability" button text
//not sure what to do with this code snippet? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/
add_filter( 'woocommerce_booking_single_check_availability_text', 'wooninja_booking_check_availability_text' );
function wooninja_booking_check_availability_text() {
return "MY CUSTOM TEXT";
}
@WillBrubaker
WillBrubaker / gist1.php
Created September 4, 2015 02:08
Apply WooCommerce Membership discount to a Subscription sign-up fee
add_filter( 'woocommerce_subscriptions_product_sign_up_fee', 'handsome_bearded_guy_filter_sign_up_fee', 10, 2 );
function handsome_bearded_guy_filter_sign_up_fee( $subscription_sign_up_fee, $product ) {
//this will only work if the necessary object and method are present
if ( class_exists( 'WC_Memberships_Member_Discounts' ) && method_exists( 'WC_Memberships_Member_Discounts', 'get_discounted_price' ) ) {
$discounter = new WC_Memberships_Member_Discounts;
//taken from WooCommerce Memberships
/**
* Get product discounted price for member
*
@WillBrubaker
WillBrubaker / removecompletedtorrents.sh
Created March 29, 2016 20:19 — forked from bulljit/removecompletedtorrents.sh
Transmission-Daemon: Remove Completed Torrents
#!/bin/sh
# script to check for complete torrents in transmission folder, then stop and move them
# either hard-code the MOVEDIR variable here…
MOVEDIR=/home/mjdescy/media # the folder to move completed downloads to
# …or set MOVEDIR using the first command-line argument
# MOVEDIR=%1
# use transmission-remote to get torrent list from transmission-remote list
# use sed to delete first / last line of output, and remove leading spaces
# use cut to get first field from each line
@WillBrubaker
WillBrubaker / gist.php
Last active September 30, 2022 20:32
Dynamically Change WooCommerce Order Date on Status Change
add_action( 'woocommerce_loaded', 'handsome_bearded_guy_wc_loaded' );
function handsome_bearded_guy_wc_loaded() {
$old_statuses = array(
'failed',
//uncomment any of the below statuses to include those statuses
//'pending',
//'processing',
//'on-hold',
//'cancelled',
@WillBrubaker
WillBrubaker / custom-my-account-endpoint.php
Last active July 18, 2017 13:17 — forked from claudiosanches/custom-my-account-endpoint.php
Example of custom My Account endpoint.
<?php
class My_Custom_My_Account_Endpoint {
/**
* Custom endpoint name.
*
* @var string
*/
public static $endpoint = 'my-custom-endpoint';