Skip to content

Instantly share code, notes, and snippets.

@jessepearson
jessepearson / wc_auto_complete_virtual.php
Created July 4, 2016 20:38
Auto Complete all WooCommerce virtual orders
<?php // only copy this line if needed
/**
* Auto Complete all WooCommerce virtual orders.
*
* @param int $order_id The order ID to check
* @return void
*/
function custom_woocommerce_auto_complete_virtual_orders( $order_id ) {
@jessepearson
jessepearson / wc_auto_complete_virtual_with_payment_method.php
Created July 5, 2016 20:39
Auto Complete all WooCommerce virtual orders if payment methods match.
<?php // only copy if needed
/**
* Auto Complete all WooCommerce virtual orders if payment methods match.
*
* @param int $order_id The order ID to check
* @return void
*/
function custom_woocommerce_auto_complete_virtual_orders( $order_id ) {
@jessepearson
jessepearson / gist:852447a86511b0ed7b2ace684b111da1
Last active July 20, 2016 21:35
Filter to modify query for posts/content shown in My Membership area
<?php
/**
* Filter restricted content query args
*
* @since 1.6.3
* @param array $query_args Args passed to WP_Query
* @param string $query_type Type of request: 'content_restriction', 'product_restriction', 'purchasing_discount'
* @param int $query_paged Pagination request
*/
$query_args = apply_filters( 'wc_memberships_get_restricted_posts_query_args', $query_args, $type, $paged );
@jessepearson
jessepearson / remove_free_as_grouped_product_price.php
Created July 29, 2016 14:55
Remove 'Free!' as the price for grouped products
<?php // do not copy this line unless needed
/**
* Remove 'Free!' as the price for grouped products
*
* @param $price string The price
* @param $prod object The product
* @return string The original or modified price.
*/
function remove_free_as_grouped_product_price( $price, $prod ) {
@jessepearson
jessepearson / adjust_local_pickup_tax_address_for_avatax.php
Last active January 3, 2018 16:55
This function will set the tax address for WooCommerce AvaTax when local_pickup is chosen
<?php // only copy this line if needed
/**
* This function will set the tax address for WooCommerce AvaTax when local_pickup is chosen
*
* @param $address array The orignal address
* @return array The original or modified address.
*/
function adjust_local_pickup_tax_address_for_avatax( $address ) {
// get the chosen shipping method
@jessepearson
jessepearson / add_bcc_to_certain_emails.php
Created October 31, 2016 17:19
Add a BCC to certain defined emails sent from WooCommerce
<?php // only copy this line if needed
/**
* Function adds a BCC header to emails that match our array
*
* @param string $headers The default headers being used
* @param string $object The email type/object that is being processed
*/
function add_bcc_to_certain_emails( $headers, $object ) {
@jessepearson
jessepearson / lets-confirm-some-cod-bookings.php
Last active August 7, 2023 14:47
Place Bookings into a confirmed status if they have been paid for via COD - for WooCommerce Bookings
<?php // only copy this line if needed
// related blog post: https://jessepearson.net/2016/11/woocommerce-bookings-cod-payments/
/**
* Function that will put bookings into a Confirmed status if they were paid for via COD
*
* @param int/string $order_id The order id
* @return null
*/
function lets_confirm_some_cod_bookings( $order_id ) {
global $wpdb;
@jessepearson
jessepearson / increase-variation-threshold.php
Last active March 29, 2022 17:46
Increase the number of variations loaded in the WooCommerce front end for dynamic filtering of available variations in the drop down lists.
<?php //only copy this line if needed
/**
* Function filters the threshold for the amount of variables to load in the front end.
*
* @see https://woocommerce.wordpress.com/2015/07/13/improving-the-variations-interface-in-2-4/
*
* @return int 100 The new threshold.
*/
add_filter( 'woocommerce_ajax_variation_threshold', function() { return 100; } );
@jessepearson
jessepearson / lets_replace_free_with_zeros.php
Last active November 22, 2016 19:15
Function filters the price of products looking for "Free!" and replaces it with "$0.00"
<?php // copy this line only if needed, usually it's not needed
/**
* Function filters the price of products looking for "Free!" and replaces it with "$0.00"
*
* @param string $price The price being passed
* @param object $product The product we're looking at
* @return string The filtered price
*/
function lets_replace_free_with_zeros( $price, $product ) {
@jessepearson
jessepearson / move_bookings_calendar_to_first_available_block.php
Created January 3, 2017 20:17
Filter to tell Bookings to show the calendar month when the first block is available
<?php // Do not copy this line unless needed
/**
* As of Bookings 1.9.13 the current date will be shown in the calendar for performance reasons.
* To return to the previous functionality, a filter was put in place. The below function uses this
* filter to tell Bookings to show the calendar month when the first block is available.
* @param bool $move - This is here just to prevent errors
* @return bool false for first block's month, true for current month
*/
function move_bookings_calendar_to_first_available_block( $move ) {