Skip to content

Instantly share code, notes, and snippets.

@thisissandip
thisissandip / booking-creation-logger.php
Last active April 7, 2025 10:42
booking-creation-logger: Logs details of the new booking in WooCommerce > status > logs
/**
* Monitor new booking creation using wc_get_logger
*/
function log_all_new_bookings( $booking_id ) {
if ( ! function_exists( 'get_wc_booking' ) ) {
return;
}
$booking = get_wc_booking( $booking_id );
@thisissandip
thisissandip / block_resources.php
Created March 18, 2025 11:03
WooCommerce Bookings: Automatically Block Other Resources When One is Booked
/*
This snippet ensures that when a booking is paid for a booking product with multiple resources,
all other linked resources are automatically blocked for the same time slot. It dynamically adds
an availability rule within the booking product blocking the slot, preventing other resources bookings for that slot.
*/
function block_booking_slot_to_prevent_other_resource_bookings_on_payment($booking_id) {
@thisissandip
thisissandip / auto_select_booking_first_available_date
Last active June 10, 2024 07:31
Auto Select the first available booking date in WooCommerce Booking Calendar
add_action( 'wp_footer', 'bookable_product_script_js');
function bookable_product_script_js() {
global $product;
// Only on single bookable products
if( is_product() && $product->is_type('booking')) :
?>
<script type='text/javascript'>
var interval = setInterval(checkifDateisLoaded, 500); // set booking calendar load time
function checkifDateisLoaded() {
const datetobeselected = document.querySelector("[title='This date is available']");
@thisissandip
thisissandip / share_woocommerce_cart.php
Last active February 4, 2024 07:28
The cart page features a "Share Cart" button, allowing admins to generate a unique cart URL for easy cart sharing with customers. Additionally, admins can manage generated cart URLs by clearing them from the "WC > Status > Tools" section.
<?php
/**
* Function to get cart data from session
*
*/
function get_cart_data_from_session(){
$cart_session = array(
'cart' => '',
'cart_totals' => '',
@thisissandip
thisissandip / Remove WooCommerce Bookings "Templates" tab
Created November 3, 2023 14:11
Remove WooCommerce Bookings "Templates" tab
function remove_tab_7252021 ($tabs){
unset($tabs['bookings_templates']);
return($tabs);
}
add_filter('woocommerce_product_data_tabs', 'remove_tab_7252021', 10, 1);
@thisissandip
thisissandip / class-wc-bookings-create.php
Created September 4, 2023 14:27
Modified class-wc-bookings-create.php - it saves the manually created order after adding the item meta
<?php
/**
* Create new bookings page.
*/
class WC_Bookings_Create {
/**
* Stores errors.
*
* @var array
@thisissandip
thisissandip / Remove WooCommerce On Hold emails sent to Vendors
Created July 27, 2023 06:33
Unhooks the WooCommerce Order emails sent to Vendors if the order is on hold
/* Remove WooCommerce On Hold emails sent to Vendors */
add_action( 'woocommerce_email', 'unhook_vendor_new_order_email_if_order_is_on_hold' );
function unhook_vendor_new_order_email_if_order_is_on_hold( $email_class ) {
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Product_Vendors_Order_Email_To_Vendor'], 'trigger' ) );
}
@thisissandip
thisissandip / gist:a0137018c26f7c16c18f35ed56d1027c
Last active July 11, 2023 09:18
WooCommerce Bookings: Keep the booking in cart if the order fails
/*
Removes "schedule_failed_order_event" handler which marks the booking as unpaid after
an order fails and expires the booking after an hour.
In place of the above handle, the below snippet adds a custom handler that updates the booking status to "in-cart"
such that customer can retry payment for the booking.
*/
remove_action('woocommerce_order_status_failed', 'schedule_failed_order_event');
@thisissandip
thisissandip / Forums notice - Escalate to PA View
Created August 30, 2022 06:52
Forums notice - Escalate to PA View
// ==UserScript==
// @name WordPress.org Escalate to PAs
// @description Check if this is a forum revie
// @include https://*.wordpress.org/support/topic/*
// @include https://*.wordpress.org/support/view/*
// @include https://wordpress.org/support/topic/*
// @include https://wordpress.org/support/view/*
// @require https://code.jquery.com/jquery-1.11.0.min.js
// ==/UserScript==
@thisissandip
thisissandip / Move Payment Request Buttons button - WC Stripe.txt
Last active August 5, 2023 08:28
Move Payment Request Buttons button - WC Stripe
/**
* Move Payment Request Buttons button - Stripe
*/
function move_woocommerce_stripe_payment_request_buttons() {
$PaymentReqBtnInst = WC_Stripe_Payment_Request::instance();
//Checkout Page
remove_action( 'woocommerce_checkout_before_customer_details', array( $PaymentReqBtnInst, 'display_payment_request_button_separator_html' ), 2 );
remove_action( 'woocommerce_checkout_before_customer_details', array( $PaymentReqBtnInst, 'display_payment_request_button_html' ), 1 );