Skip to content

Instantly share code, notes, and snippets.

View stuartduff's full-sized avatar

Stuart Duff stuartduff

View GitHub Profile
@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 / woocommerce-bookings-change-single-add-to-cart-text.php
Created April 20, 2016 13:43
Change WooCommerce Bookings single add to cart text "Book Now"
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 / 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-custom-homepage-shortcode-section.php
Created December 8, 2015 22:53
Add a custom shortcode section to the storefront themes homepage template.
function sf_output_custom_shortcode_section() {
echo '<section class="storefront-product-section storefront-product-category">';
echo '<h2 class="section-title">' . __( 'Music Category', 'storefront' ) . '</h2>';
echo do_shortcode( '[product_category category="music" columns="4" per_page="4"]' );
echo '</section>';
@stuartduff
stuartduff / translate.php
Last active July 17, 2022 14:34
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.
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 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-exclude-product-category-from-shop-page.php
Last active May 6, 2022 00:20
This snippet will exclude all products from any categories which you choose from displaying on the WooCommerce Shop page.
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 / storefront-remove-secondary-menu
Created April 5, 2016 15:09
Storefront theme remove the secondary menu with and add_action();
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 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 / storefront-four-homepage-product-categories.php
Created April 6, 2016 12:45
Storefront display four product categories on the homepage.
/**
* 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;