Skip to content

Instantly share code, notes, and snippets.

Avatar

Stuart Duff stuartduff

View GitHub Profile
@stuartduff
stuartduff / woocommerce-bookings-change-single-add-to-cart-text.php
Created Apr 20, 2016
Change WooCommerce Bookings single add to cart text "Book Now"
View woocommerce-bookings-change-single-add-to-cart-text.php
function change_booking_single_add_to_cart_text() {
echo 'Changed Text';
}
add_filter( 'woocommerce_booking_single_add_to_cart_text','change_booking_single_add_to_cart_text' );
@stuartduff
stuartduff / translate.php
Last active Jul 17, 2022
WordPress Translate Text testing Snippet - this snippet when added to a themes functions.php file will let you test if the Localization of a word or text string is taking effect and changing within a theme or plugin without using the translation .MO and .PO files.
View translate.php
function translate_text( $translated ) {
// The first parameter is the original text, the second parameter is the changed text.
$translated = str_ireplace( 'Choose and option', 'Select', $translated );
// Returns the translated text
return $translated;
}
add_filter( 'gettext', 'translate_text' );
@stuartduff
stuartduff / storefront-header-category-image.php
Created Jun 21, 2022
Add WooCommerce product category image full width under the header of the Storefront theme.
View storefront-header-category-image.php
/**
* 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-exclude-product-category-from-shop-page.php
Last active May 6, 2022
This snippet will exclude all products from any categories which you choose from displaying on the WooCommerce Shop page.
View wc-exclude-product-category-from-shop-page.php
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'clothing' ), // Don't display products in the clothing category on the shop page.
'operator' => 'NOT IN'
);
@stuartduff
stuartduff / wc-add-webp-mime-type-import-support.php
Last active May 5, 2022
Add webp MIME to be supported with the default WooCommerce Product Importer
View wc-add-webp-mime-type-import-support.php
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 / storefront-remove-secondary-menu
Created Apr 5, 2016
Storefront theme remove the secondary menu with and add_action();
View storefront-remove-secondary-menu
function remove_storefront_default_actions() {
remove_action( 'storefront_header' , 'storefront_secondary_navigation' , 30 );
}
add_action( 'init', 'remove_storefront_default_actions' );
@stuartduff
stuartduff / wc-composite-products-change-select-options-text.php
Created Feb 17, 2022
Change the text for the Select Options button when using Composite Products
View wc-composite-products-change-select-options-text.php
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 / storefront-four-homepage-product-categories.php
Created Apr 6, 2016
Storefront display four product categories on the homepage.
View storefront-four-homepage-product-categories.php
/**
* Alters the output of the homepage product categories on the Storefront theme
* Affects the storefront_product_categories_args filter in /inc/structure/template-tags.php
*/
function sd_display_four_home_product_categories( $args ) {
// Sets the maximum product categories to 4, you can increase this to display more if need be.
$args['limit'] = 4;
@stuartduff
stuartduff / adjust-wordpress-jpeg-image-quality.php
Created Sep 22, 2017
Adjust WordPress jpeg image quality
View adjust-wordpress-jpeg-image-quality.php
function sd_regenerate_thumbnail_quality() {
// increase or decrease from 0 to 100 for a percentage of image quality.
return 100;
}
add_filter( 'jpeg_quality', 'sd_regenerate_thumbnail_quality');
@stuartduff
stuartduff / wc-customer-cancel-payment-url.php
Created Aug 20, 2021
Set a custom return URL for canceled orders on WooCommerce
View wc-customer-cancel-payment-url.php
/* 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";
}