Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
WillBrubaker / file.php
Created April 25, 2018 12:47
WooCommerce Stripe Force 3D Secure
/* Not sure what to do with these code snippets? See: https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/ */
add_filter( 'wc_stripe_require_3ds', 'handsome_beardedguy_maybe_force_3ds', 10, 2 );
function handsome_beardedguy_maybe_force_3ds( $required, $source_object ) {
return ( is_object( $source_object ) && property_exists( $source_object, 'card' ) && 'optional' === $source_object->card->three_d_secure ) ? true : $required;
}
@WillBrubaker
WillBrubaker / file.php
Created March 15, 2018 13:54
WooCommerce Bookings: Remove all available blocks for the day if one is booked
//Don't know what to do with this? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/
add_filter( 'wc_bookings_product_get_available_blocks', 'beardedguy_maybe_remove_availability', 10, 5 );
function beardedguy_maybe_remove_availability( $available_blocks, $booking_object, $blocks, $intervals, $resource_id ) {
return ( sizeof( $available_blocks ) < sizeof( $blocks ) ) ? array() : $available_blocks;
}
@WillBrubaker
WillBrubaker / file.php
Created April 27, 2017 17:42
Display WooCommerce Photography Products in Shop
add_action( 'pre_get_posts', 'handsome_bearded_guy_show_photograhpy_products', 99 );
function handsome_bearded_guy_show_photograhpy_products( $query ) {
if ( ! $query->is_main_query() || is_admin() ) {
return;
}
if ( isset( $query->query_vars['tax_query'] ) && is_post_type_archive( 'product' ) || ( is_page() && isset( $query->query_vars['page_id'] ) && wc_get_page_id( 'shop' ) == $query->query_vars['page_id'] ) && ! is_search() ) {
foreach ( $query->query_vars['tax_query'] as $key => $arr ) {
if ( in_array( 'photography', $arr['terms'] ) ) {
add_filter( 'booking_form_fields', 'handsomebeardedguy_booking_form_fields' );
function handsomebeardedguy_booking_form_fields( $fields ) {
if ( isset( $fields['wc_bookings_field_resource'] ) ) {
$pattern = '#\(\+*.*\)#';
$replacement = '';
foreach ( $fields['wc_bookings_field_resource']['options'] as $key => $value ) {
$fields['wc_bookings_field_resource']['options'][ $key ] = preg_replace( $pattern, $replacement, $value );
}
}
@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';
@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 / 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 / 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 / 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 / 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;
}