Code snippets

You are here:
Estimated reading time: 1 min

Most of these codes should be pasted into wp-content/themes/rey-child/functions.php .

Show Wishlist icon on products when in Catalogue Mode

Catalogue mode* is when Ecommerce functionality is disabled.

add_action('wp', function(){
	if( class_exists('WooCommerce') && class_exists('TInvWL_Public_AddToWishlist') && is_product() ) {
		$product = wc_get_product();
		if( ! $product->is_purchasable() && ($product->get_regular_price() || $product->get_sale_price()) ) {
			add_action( 'woocommerce_single_product_summary', function(){
				echo do_shortcode("[ti_wishlists_addtowishlist]");
			}, 20 );
		}
	}
});

Replace 180 with another size.

add_filter('woocommerce_get_image_size_gallery_thumbnail', function ($size){
	$cropping['width'] = max( 1, get_option( 'woocommerce_thumbnail_cropping_custom_width', '4' ) );
	$cropping['height'] = max( 1, get_option( 'woocommerce_thumbnail_cropping_custom_height', '3' ) );
	$size['width']  = 180;
	$size['height'] = ($cropping['height'] / $cropping['width']) * $size['width'];
	$size['crop']   = 1;
    return $size;
}, 10);

add_filter( 'woocommerce_breadcrumb_defaults', function($args){
	if( is_product() ){
		$args['home'] = _x( 'Home', 'breadcrumb', 'rey-core' );
		return $args;
	}
},20);

Slow Customizer? Disable the preview iframe.

add_action('customize_controls_print_footer_scripts', function(){
	?>
	<script>
		document.addEventListener('DOMContentLoaded', function(){
			document.getElementById('customize-preview').remove();
		});
	</script>
	<?php
});

Remove price from loop & product page

add_action('wp', function(){
    remove_action('reycore/woocommerce/after_shop_loop_item', 'woocommerce_template_loop_price', 10);
    remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_price', 60);
    remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
});

Add WooCommerce Multilingual Currency Switcher into Default Header


// Adds the currency switcher in the header
add_action('rey/header/row', function(){

    // This shortcode adds the Currency switcher
    // but too much text is shown
    //echo do_shortcode('[currency_switcher]');

    // instead show only what matters
    do_action('wcml_currency_switcher', array(
        'format' => '%code% (%symbol%)'
    ));

}, 70);

And also some fine tuning CSS in Customizer > Additional CSS

.wcml_currency_switcher {
    margin-left: 1.5rem;
    width: auto;
}

These codes apply for the Default header, when it’s non Global Section. If you’re using a Header Global Section, simply add a Shortcode element into the Header section and paste the shortcode eg: [currency_switcher] .

Was this article helpful?
Dislike 0
Views: 20

Join the conversation