Skip to content

Instantly share code, notes, and snippets.

View stuartduff's full-sized avatar

Stuart Duff stuartduff

View GitHub Profile
@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' );
@stuartduff
stuartduff / tenp-bookings-price-fix.php
Last active December 15, 2022 16:09
Remove the word From: before WooCommerce Bookings Price [Temp Fix #3459]
/**
* Temp Fix for the Bookings issue below.
* #3459
*/
function temp_price_fix_bookings( $price, $product ) {
$target_product_types = array(
'booking'
);
@stuartduff
stuartduff / temp-composite.sort-by-text.php
Created October 20, 2022 13:57
Temporary fix for Composite Products Sort by newness to Sort by latest text
/**
* Temporary fix for Composite Products Sort by newness to Sort by latest text
*/
function temp_order_by_text_tweak( $orderby_options ) {
$orderby_options['date'] = __( 'Sort by latest', 'woocommerce' );
return $orderby_options;
@stuartduff
stuartduff / storefront-header-category-image.php
Created June 21, 2022 15:46
Add WooCommerce product category image full width under the header of the Storefront theme.
/**
* Add WooCommerce product category image full width under the header of the Storefront theme.
*/
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
@stuartduff
stuartduff / wc-add-webp-mime-type-import-support.php
Last active February 17, 2024 20:26
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-composite-products-change-select-options-text.php
Created February 17, 2022 14:43
Change the text for the Select Options button when using Composite Products
add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
global $product;
if ( $product->is_type( 'composite' ) ) {
$text = $product->is_purchasable() ? __( 'Custom options text', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
}
return $text;
}, 10 );
@stuartduff
stuartduff / wc-customer-cancel-payment-url.php
Created August 20, 2021 09:03
Set a custom return URL for canceled orders on WooCommerce
/* Paypal cancel order redirect */
add_filter( 'woocommerce_get_cancel_order_url_raw', 'paypal_canceled_redirect' );
function paypal_canceled_redirect(){
// Replace the URL below with the one you'd like to return to after a canceled order.
return "https://woocommerce.com";
}