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 );
		}
	}
});

Force custom height & cropping in product page images

Replace 400 height with another size. It might be needed to regenerate, so you can try accessing WooCommerce > Status > Tools > Regenerate eg: https://d.pr/i/aKwJ8K .

add_filter('woocommerce_get_image_size_single', function($size){
  $size['width']  = absint( wc_get_theme_support( 'single_image_width', get_option( 'woocommerce_single_image_width', 600 ) ) );
  $size['height'] = 400;
  $size['crop']   = 1;
  return $size;
});

Replace 180 with another size. It might be needed to regenerate, so you can try accessing WooCommerce > Status > Tools > Regenerate eg: https://d.pr/i/aKwJ8K .

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] .

Prevent opening cart panel on single product page, on mobiles

Add this code into rey-child/functions.php

add_action('wp_footer', function(){
	?>
	<script>
		jQuery(document).on('ready', function(){

			var $atcBtn = jQuery(".single_add_to_cart_button.button");

			var addPreventClass = function(){
				if( ! jQuery.reyHelpers.is_desktop ){
					$atcBtn.addClass('--prevent-open-cart');
				}
			};

			addPreventClass();

			jQuery(document).on("woocommerce_variation_has_changed", ".variations_form", function (e) {
				addPreventClass();
			});
		});
	</script>
	<?php
}, 999);

Change Add To Cart button bg-color in single product pages

.woocommerce div.product .rey-cartBtnQty {
  --accent-color: #cf2929;
}
Was this article helpful?
Dislike 0
Views: 56

Join the conversation