Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
WillBrubaker / file.php
Last active April 9, 2024 18:44
WooCommerce Colorado Retail Delivery Fee
// not sure what to do with this code snippet? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/
// BTC Donations to: bc1q0cwjuxxqqmwnxxc0m2xkkyf4kes9e0gejc9u0l
/**
* Add a .27 surcharge to orders shipping to Colorado
*/
add_action('woocommerce_cart_calculate_fees', 'handsome_bearded_guy_custom_surcharge');
function handsome_bearded_guy_custom_surcharge() {
global $woocommerce;
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 / file.php
Created March 29, 2021 04:30
Conditionally hide shipping methods if payment request button is used for payment
// not sure what to do with this code snippet? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/
// BTC Donations to: bc1qc2s60yct2aqza4r7ryweheepd8xa8wqpfgdhg3
//hook into wc_ajax_wc_stripe_get_shipping_options
add_action( 'wc_ajax_wc_stripe_get_shipping_options', 'handsome_bearded_guy_filter_shipping_methods' );
function handsome_bearded_guy_filter_shipping_methods() {
//hook into woocommerce_shipping_methods
add_filter( 'woocommerce_shipping_methods', 'handsome_bearded_guy_remove_shipping_methods' );
}
@WillBrubaker
WillBrubaker / gist:7246ea87ea88d593b752
Last active May 10, 2023 08:36
Echos out confirmation JavaScript on WooCommerce My Account Page
add_action( 'woocommerce_after_my_account', 'handsomebeardedguy_after_my_account' );
add_action( 'woocommerce_subscription_details_after_subscription_table', 'handsomebeardedguy_after_my_account' );
function handsomebeardedguy_after_my_account() {
echo '<script>
jQuery(document).ready(function($) {
$("td.subscription-actions a.cancel, table.shop_table.subscription_details a.cancel").on("click", function(e) {
var confirmCancel = confirm("Are you sure you want to cancel this subscription? This action is not reversible")
if (!confirmCancel) {
e.preventDefault()
@WillBrubaker
WillBrubaker / pre-option.php
Last active March 27, 2023 23:12
An example of the use of the pre_option_ WordPress filter
<?php
add_action( 'pre_get_posts', 'wwm_pre_get_posts', 10, 0 );
function wwm_pre_get_posts() {
/**
* For this example, the plugin that would be altered is the 'featured video plus' plugin
* The task is to show the featured video on single pages, but not on archives
* apply the filter on singlular pages that aren't the admin interface.
*/
@WillBrubaker
WillBrubaker / key.md
Created February 4, 2023 08:23
Twitter (un)official Consumer Key

Twitter Official Consumer Key

Twitter for Android

type:            PIN
Consumer key:    3nVuSoBZnx6U4vzUxf5w
Consumer secret: Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys

Twitter for iPhone

type:            PIN

Consumer key: IQKbtAYlXLripLGPWd0HUA

@WillBrubaker
WillBrubaker / remove-woocommerce-submenu-items
Last active November 22, 2022 13:34
Remove WooCommerce submenu items for Shop Managers
<?php
/*
Don't copy the opening php tag
*/
/*
Removes submenu items from WooCommerce menu for 'Shop Managers'
available submenu slugs are:
wc-addons - the Add-ons submenu
wc-status - the System Status submenu
@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 / file.php
Created December 12, 2018 11:35
WooCommerce redirect to cart if trying to add a 'sold individually' item that is already in the cart
//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_add_to_cart_sold_individually_found_in_cart', 'handsome_bearded_guy_maybe_redirect_to_cart' );
function handsome_bearded_guy_maybe_redirect_to_cart( $found_in_cart ) {
if ( $found_in_cart ) {
wp_safe_redirect( wc_get_page_permalink( 'cart' ) );
exit;
}
@WillBrubaker
WillBrubaker / snippet.php
Created September 7, 2021 03:57
Send custom price to WooCommerce Google Listings and Ads
// not sure what to do with this code snippet? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/
// BTC Donations to: bc1qc2s60yct2aqza4r7ryweheepd8xa8wqpfgdhg3
/**
* Send Custom Price to WooCommerce Google Listings and Ads
*/
add_filter( 'woocommerce_gla_product_attribute_value_price', 'handsome_bearded_guy_custom_gla_price' );
function handsome_bearded_guy_custom_gla_price( $price ) {
return ( $price * .9 );
}