Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
WillBrubaker / subscriptions-remove-strings.php
Created October 29, 2014 19:45
For WooCommerce Subscriptions, removes some of the strings during on the checkout page
<?php
/*
Don't copy the opening PHP tag
*/
add_filter( 'woocommerce_cart_item_subtotal', 'wooninja_display_subtotal', 20, 1 );
add_filter( 'woocommerce_cart_subtotal', 'wooninja_display_subtotal', 20, 1 );
add_filter( 'woocommerce_cart_total', 'wooninja_display_subtotal', 20, 1 );
function wooninja_display_subtotal( $subtotal ) {
@WillBrubaker
WillBrubaker / custom-durations.php
Last active August 29, 2015 14:09
Adds custom durations to woocommerce-subscriptions
<?php
//* Do NOT include the opening php tag
add_filter( 'woocommerce_subscription_lengths', 'wooninja_custom_subscription_duration' );
/**
* Filters the subscription lengths available
* @param array $ranges the array of ranges (lengths)
* @return array $ranges the filtered array of ranges (lengths)
*/
@WillBrubaker
WillBrubaker / num-answers-snippet.php
Created November 30, 2014 14:30
Customize the number of possible answers for questions with options (radio, checkbox, select) in Awesome Surveys survey builder
<?php
/*
Don't copy the opening php tag
*/
/*
The filter 'wwm_as_admin_script_vars' was added in version 1.6 of Awesome Surveys.
This is a sample of it's implementation. If you're comfortable with editing PHP files, use the snippet below.
It's usually recommended that these types of snippets be placed in your theme's functions.php file,
but I personally don't think that's a good idea since depending on how the theme update works you may
@WillBrubaker
WillBrubaker / bookings-label-filter.php
Created December 15, 2014 18:38
Filter WooCommerce bookings label
<?php
/*
Change the 'Persons' label to 'Qty. of Chairs'
*/
add_filter( 'booking_form_fields', 'wooninja_booking_form_fields' );
function wooninja_booking_form_fields( $fields ) {
$fields['wc_bookings_field_persons']['label'] = 'Qty. of Chairs';
return $fields;
}
@WillBrubaker
WillBrubaker / full-country-name
Created December 17, 2014 20:14
Custom CSV output for the WooCommerce Customer/Order CSV Exporter
<?php
// Add custom column headers to CSV Export.
function wc_csv_export_modify_column_headers( $column_headers ) {
$new_headers = array(
'shipping_country_name' => 'shipping_country_name'
// add other column headers here in the format column_key => Column Name
);
return array_merge( $column_headers, $new_headers );
}
@WillBrubaker
WillBrubaker / nyp-disable-input.js
Created December 24, 2014 18:00
WooCommerce Name Your Price - disable input
jQuery(document).ready(function($) {
//get the price in the input
var originalPrice = $('input#nyp').val()
var newPrice = originalPrice;
//need the product id so a cookie can be set against it, probably won't work if I change themes - but works with storefront
var productId = parseInt($('main#main > div').attr('id').replace('product-', ''))
//does a cookie exist for this product id?
var cookie = getCookie('haggledon-' + productId)
if (cookie != null) {//the cookie exists, therefore this person has 'haggled' within 24 hours. Disable the price input.
@WillBrubaker
WillBrubaker / wc-nyp-disable-input.js
Last active August 29, 2015 14:12
WooCommerce Name Your Price - disable input
jQuery(document).ready(function($) {
//re-assign the error message variable - keep the minimum acceptable price concealed
if ( 'undefined' != typeof woocommerce_nyp_params ) {
woocommerce_nyp_params.minimum_error = 'Offer rejected';
}
//initially disable the price input
$('input#nyp').prop('disabled', true)
// WooCommerce outputs the product id in a hidden element within the add to cart form.
var productId = $('input[name="add-to-cart"]').val()
@WillBrubaker
WillBrubaker / search.php
Last active August 29, 2015 14:12
Override Default Search with WooCommerce Product Search
<?php
if ( function_exists( 'woocommerce_product_search' ) ) {
echo woocommerce_product_search();
} else {
//the original contents of search.php should follow
//make sure to close the php tag as appropriate
@WillBrubaker
WillBrubaker / gist:40a8da1269ba8657dd6a
Last active August 29, 2015 14:20
redirects WooCommerce my account page to the default WordPress login if user is not logged in
<?php
//don't include the opening PHP tag
add_action( 'template_redirect', 'handsomebeardedguy_redirect_myaccount' );
function handsomebeardedguy_redirect_myaccount() {
if ( function_exists( 'is_account_page' ) && is_account_page() && ! is_user_logged_in() ) {
wp_redirect( wp_login_url( get_permalink( wc_get_page_id( 'shop' ) ) ) );
exit;
}
}
@WillBrubaker
WillBrubaker / gist:2bf13e141a739b612b67
Last active January 28, 2017 08:28
Removes cost indicator from WooCommerce Bookings resources dropdown
add_filter( 'booking_form_fields', 'handsomebeardedguy_booking_form_fields' );
function handsomebeardedguy_booking_form_fields( $fields ) {
if ( isset( $fields['wc_bookings_field_resource'] ) ) {
$pattern = '#\(\+<span class="amount">.*\)#';
$replacement = '';
foreach ( $fields['wc_bookings_field_resource']['options'] as $key => $value ) {
$fields['wc_bookings_field_resource']['options'][ $key ] = preg_replace( $pattern, $replacement, $value );
}
}