Skip to content

Instantly share code, notes, and snippets.

View stuartduff's full-sized avatar

Stuart Duff stuartduff

View GitHub Profile
@stuartduff
stuartduff / wcbo-link-guest-tickets-to-registered-users.php
Last active August 8, 2025 15:56
WooCommerce Box Office - Link Guest Tickets to Registered Users
@stuartduff
stuartduff / wc-customer-invoice-cc.php
Created November 2, 2024 14:40
CC Email into WooCommere Customer Invoice Email
function add_cc_to_invoice_email($headers, $email_id, $order) {
if ($email_id === 'customer_invoice') {
$cc_email = 'cc@example.com'; // Replace with the email you want to CC
$headers .= 'Cc: ' . $cc_email . "\r\n";
}
return $headers;
}
add_filter('woocommerce_email_headers', 'add_cc_to_invoice_email', 10, 3);
@stuartduff
stuartduff / wc-add-webp-mime-type-import-support.php
Last active October 15, 2024 13:37
Add webp MIME to be supported with the default WooCommerce Product Importer
function add_additonal_wc_mime_types($mime_types) {
$mime_types['webp'] = 'image/webp'; // Add support for webp images in the WooCommerce Product importer.
return $mime_types;
}
add_filter('woocommerce_rest_allowed_image_mime_types', 'add_additonal_wc_mime_types', 1, 1);
@stuartduff
stuartduff / wc-stripe-add-product-metadata.php
Last active February 19, 2024 22:49
WooCommerce Stripe Add "Products" to Stripe Payment metadata
/*
* Add "Products" to Stripe metadata
*/
function filter_wc_stripe_payment_metadata( $metadata, $order, $source ) {
$count = 1;
foreach( $order->get_items() as $item_id => $line_item ){
$item_data = $line_item->get_data();
$product = $line_item->get_product();
$product_name = $product->get_name();
@stuartduff
stuartduff / wc-subscriptions-only-allow-one-subscription.php
Created May 6, 2021 15:09
This code snippet for WooCommerce Subscriptions will only allow a single purchased subscription across all subscription products for customers.
add_filter('woocommerce_add_to_cart_validation', 'check_num_of_subscriptions', 10, 2);
function check_num_of_subscriptions( $valid, $product_id )
{
$product_to_add = wc_get_product( $product_id );
if ( $product_to_add instanceof WC_Product_Subscription || $product_to_add instanceof WC_Product_Variable_Subscription) {
// alternative use: $has_sub = wcs_user_has_subscription( '', '', 'active' );
if ( has_active_subscription() ) {
@stuartduff
stuartduff / reverse-woocommerce-reviews-order.php
Created December 9, 2015 15:23
This snippet will reverse the display order of the WooCommerce product reviews
// show newest product reviews on top
function sd_newest_reviews_first( $args ) {
$args['reverse_top_level'] = true;
return $args;
}
add_filter( 'woocommerce_product_review_list_args', 'sd_newest_reviews_first' );
@stuartduff
stuartduff / remove-my-account-downloads-menu.php
Created May 2, 2023 16:08
Remove WooCommerce Downloads menu item from My Account page.
function custom_my_account_menu_items( $items ) {
unset($items['downloads']);
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'custom_my_account_menu_items' );
@stuartduff
stuartduff / remove-storefront-theme-handheld-search-icon.php
Created April 12, 2023 12:55
Remove Storefront theme handheld search icon
function remove_handheld_search( $links ) {
unset( $links['search'] );
return $links;
}
add_filter( 'storefront_handheld_footer_bar_links', 'remove_handheld_search' );
@stuartduff
stuartduff / gist:7b5d1f85bd29917fb9f9eca395d306f5
Created March 15, 2023 13:09
Replace Storefront Header Search With Default WordPress Search Widget
function storefront_product_search() {
if ( storefront_is_woocommerce_activated() ) {
?>
<div class="site-search">
<?php the_widget( 'WP_Widget_Search', 'title=' ); ?>
</div>
<?php
}
}
function remove_wc_stripe_from_checkout_page( $available_gateways ) {
unset( $available_gateways['stripe'] );
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'remove_wc_stripe_from_checkout_page' );