Skip to content

Instantly share code, notes, and snippets.

@jessepearson
jessepearson / acf-update-via-json.php
Created March 24, 2015 12:58
Automatically update Advanced Custom Fields field groups via JSON
<?php
/**
* Function that will automatically update ACF field groups via JSON file update.
*
* @link http://www.advancedcustomfields.com/resources/synchronized-json/
*/
function jp_sync_acf_fields() {
// vars
@jessepearson
jessepearson / functions.php
Last active February 14, 2024 11:15
This is a filter to disable Multi-Currency in WooCommerce Payments.
<?php // Do not copy this line.
// This is a filter to disable Multi-Currency in WooCommerce Payments.
add_filter(
'pre_option__wcpay_feature_customer_multi_currency',
function ( $pre_option, $option, $default ) {
return '0';
},
10,
3
@jessepearson
jessepearson / functions.php
Last active December 28, 2023 20:50
Exclude category or tag from related products in WooCommerce
<?php // do not copy this line
/**
* Both functions below work the same, they just apply to categories and tags respectively.
* They exclude the defined IDs from being included in related products in WooCommerce.
*
* Note: The results are initially cached, so add this and then clear transients before saying it doesn't work.
*
* @link https://gist.github.com/jessepearson/dcf49d766cd1647465655fe9a14e51f2
* @param [array] $categories/$tags The array of categories or tags that are being used for related products.
@jessepearson
jessepearson / functions.php
Last active November 20, 2023 08:01
Will clear out all completed scheduled actions. Can be modified to clear out other statuses, as well.
<?php // Do not copy this line.
/**
* Will clear out all the specified completed scheduled actions, 5000 at a time.
*/
function clear_woocommerce_scheduled_actions_20200609() {
global $wpdb;
$limit = 5000;
$actions_table = $wpdb->prefix . 'actionscheduler_actions';
@jessepearson
jessepearson / woocommerce_defer_transactional_emails.php
Last active November 15, 2023 03:55
This will turn on deferred transactional emails in WooCommerce. This may help if you are experiencing slow checkouts or checkout timeouts.
<?php // Do not copy this line
/**
* This will turn on deferred transactional emails in WooCommerce. This may help if you
* are experiencing slow checkouts or checkout timeouts.
*/
add_filter( 'woocommerce_defer_transactional_emails', '__return_true' );
@jessepearson
jessepearson / bookings_calendar_default_to_first_available.php
Last active October 31, 2023 12:56
By default the current month will be shown on the WooCommerce Bookings calendar for performance reasons. This will default it to the month with the first available block.
<?php // do not copy this line
/**
* Will make the Bookings calender default to the month with the first available booking.
*/
add_filter( 'wc_bookings_calendar_default_to_current_date', '__return_false' );
@jessepearson
jessepearson / adding_new_webhook_topics.php
Last active September 14, 2023 10:27
How to add a new custom Webhook topic in WooCommerce, with example of order filtering.
<?php // do not copy this line
/**
* add_new_topic_hooks will add a new webhook topic hook.
* @param array $topic_hooks Esxisting topic hooks.
*/
function add_new_topic_hooks( $topic_hooks ) {
// Array that has the topic as resource.event with arrays of actions that call that topic.
@jessepearson
jessepearson / auto_create_followup_booking.php
Last active August 7, 2023 15:09
Automatically create a follow up booking when a booking is paid for in WooCommerce Bookings.
<?php // do not copy this line
/**
* Code goes in theme functions.php
*
* In this example we're creating a booking 1 week after a booking is paid for.
* This does not create another order or payment, just an additional booking.
* $exact is false meaning if our slot is taken, the next available slot will be used.
* @link https://docs.woocommerce.com/document/creating-bookings-programatically/
*/
@jessepearson
jessepearson / rewrite-wc-bookings-get-time-slots-html.php
Last active August 7, 2023 14:48
Make it so that all time slots in a time-based booking in WooCommerce Bookings shows how many spots remain, not just partially booked blocks.
<?php // do not copy this line
function rewrite_wc_bookings_get_time_slots_html( $block_html, $available_blocks, $blocks ) {
$block_html = '';
foreach ( $available_blocks as $block => $quantity ) {
if ( $quantity['available'] > 0 ) {
$block_html .= '<li class="block" data-block="' . esc_attr( date( 'Hi', $block ) ) . '"><a href="#" data-value="' . date( 'c', $block ) . '">' . date_i18n( get_option( 'time_format' ), $block ) . ' <small class="booking-spaces-left">(' . sprintf( _n( '%d left', '%d left', $quantity['available'], 'woocommerce-bookings' ), absint( $quantity['available'] ) ) . ')</small></a></li>';
}
@jessepearson
jessepearson / set_cod_bookings_confirmed.php
Last active August 7, 2023 14:47
Move bookings in WooCommerce Bookings to Confirmed status if they were paid for via COD.
<?php // do not copy this line
/**
* Will put bookings into a Confirmed status if they were paid for via COD.
*
* @param int $order_id The order id
*/
function set_cod_bookings_confirmed_20170825( $order_id ) {
// Get the order, then make sure its payment method is COD.