Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
WillBrubaker / select.php
Created May 13, 2015 20:08
Template override to remove WooCommerce Bookings resource cost indicator from dropdown select
<?php
extract( $field );
<p class="form-field form-field-wide <?php echo implode( ' ', $class ); ?>">
<label for="<?php echo $name; ?>"><?php echo $label; ?>:</label>
<select name="<?php echo $name; ?>" id="<?php echo $name; ?>">
<?php foreach ( $options as $key => $value ) : ?>
<?php
/*
The default file just echos out the value
this will modify that behaviour to match a pattern and replace that pattern with an empty string
@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 / my-subscriptions.php
Last active July 8, 2021 13:24
A template override to add a JavaScript confirmation pop-up to WooCommerce Subscriptions cancel button
<?php
/**
* My Subscriptions
*/
?>
<div class="woocommerce_account_subscriptions">
<h2><?php _e( 'My Subscriptions', 'woocommerce-subscriptions' ); ?></h2>
<?php if ( ! empty( $subscriptions ) ) : ?>
@WillBrubaker
WillBrubaker / gist:c94e2e55a83dc9e8658d
Created May 14, 2015 15:27
Adds user roles to the customer export when using WooCommerce Customer/Order CSV Export
add_filter( 'wc_customer_order_csv_export_customer_headers', 'wooninja_customer_headers' );
function wooninja_customer_headers( $column_headers ) {
$column_headers['user_role'] = 'user_role';
return $column_headers;
}
add_filter( 'wc_customer_order_csv_export_customer_row', 'wooninja_customer_role', 10, 2 );
function wooninja_customer_role( $customer_data, $user ) {
@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;
}
@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: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: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: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: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';
}