17 Useful Snippets To Customize YITH WooCommerce Wishlist

Table of Contents

    YITH WooCommerce Wishlist is one of the popular WooCommerce extensions with 900,000+ active installs. Customizing your YITH WooCommerce Wishlist can add a personalized touch to your online store, providing a unique user experience for your customers. Whether you want to streamline the wishlist display, modify text labels, or optimize performance, these snippets offer valuable solutions.

    In this article, we’ll explore 17 useful code snippets that empower you to tailor the YITH Wishlist plugin according to your specific needs. Let’s dive into the world of WooCommerce Wishlist customization and unlock the full potential of your WooCommerce store.

    Reduce Ajax requests Generated by Wishlist

    In instances where your e-commerce store experiences increased traffic, the Wishlist feature may generate a considerable number of Ajax requests. This surge is often a result of multiple visitor sessions, potentially causing delays in cart or checkout page loading.Since it adds pressures on server it can lead to showing 502 errors.

    To address this issue, consider disabling AJAX loading within the plugin settings. If you’ve already deactivated the AJAX setting in the general settings tab and still observe a high volume of AJAX requests, you can further reduce them by incorporating the following code into the functions.php file of your active child theme.

    This code removes the calls which are included in order to prevent the cache system from affecting the functionality of a button adding a wrong product or to the incorrect list.

    add_filter( 'yith_wcwl_reload_on_found_variation', '__return_false' );
    

    Prevent Loading Font Awesome library from YITH wishlist

    If you have your own version of FontAwesome loaded in your site,there’s no need to retain the one bundled with the YITH Wishlist plugin.

    In order to prevent the plugin from loading its library, you can add the following snippet of code at the end of functions.php file of your theme or child.

    if (!function_exists('yith_wcwl_dequeue_wishlist_font_awesome')){   add_action('wp_enqueue_scripts','yith_wcwl_dequeue_wishlist_font_awesome' );
     function yith_wcwl_dequeue_wishlist_font_awesome(){
          wp_deregister_style('yith-wcwl-font-awesome');
     }
    }

    Remove “add to wishlist” From Product Block

    In order to remove the “add to wishlist” text from the Gutenberg product block, you can add the following snippet of code at the end of functions.php file of your theme or child.

    if ( ! function_exists( 'yith_wcwl_remove_filter' ) && class_exists( 'YITH_WCWL_Frontend' ) ) {
        function yith_wcwl_remove_filter() {
            $instance = YITH_WCWL_Frontend::get_instance();
            remove_filter( 'woocommerce_blocks_product_grid_item_html', array( $instance, 'add_button_for_blocks_product_grid_item' ), 10, 3 );
        }
        add_action( 'init', 'yith_wcwl_remove_filter' );
    }

    Change the Wishlist Table Name Heading

    if ( ! function_exists( 'yith_wcwl_wishlist_view_name_heading_custom' ) ) {
        function yith_wcwl_wishlist_view_name_heading_custom() {
            return 'Product Name';
        }
        add_filter( 'yith_wcwl_wishlist_view_name_heading', 'yith_wcwl_wishlist_view_name_heading_custom', 99 );
    }

    Change the Wishlist Table Price Heading

    if ( ! function_exists( 'yith_wcwl_wishlist_view_price_heading_custom' ) ) {
        function yith_wcwl_wishlist_view_price_heading_custom() {
            return 'Price';
        }
        add_filter( 'yith_wcwl_wishlist_view_price_heading', 'yith_wcwl_wishlist_view_price_heading_custom', 99 );
    }

    Change the Wishlist Table Stock Heading

    if ( ! function_exists( 'yith_wcwl_wishlist_view_stock_heading_custom' ) ) {
        function yith_wcwl_wishlist_view_stock_heading_custom() {
            return 'Stock';
        }
        add_filter( 'yith_wcwl_wishlist_view_stock_heading', 'yith_wcwl_wishlist_view_stock_heading_custom', 99 );
    }

    Change the Wishlist Table Stock Label

    if ( ! function_exists( 'yith_wcwl_in_stock_label_custom' ) ) {
        function yith_wcwl_in_stock_label_custom() {
            return 'In stock';
        }
        add_filter( 'yith_wcwl_in_stock_label', 'yith_wcwl_in_stock_label_custom', 99 );
    }

    Change the Text “Product Name” in Wishlist Page

    In that code you can change the text to whatever you want.

    if ( ! function_exists( 'yith_wcwl_wishlist_view_name_heading_custom' ) ) {
        function yith_wcwl_wishlist_view_name_heading_custom() {
            return __( 'Product name', 'yith-woocommerce-wishlist' );
        }
        add_filter( 'yith_wcwl_wishlist_view_name_heading', 'yith_wcwl_wishlist_view_name_heading_custom', 99 );
    }

    Change “No products were added to the wishlist”

    if ( ! function_exists( 'yith_wcwl_no_product_to_remove_message_custom' ) ) {
        function yith_wcwl_no_product_to_remove_message_custom() {
            return 'No Products';
        }
    }
    add_filter( 'yith_wcwl_no_product_to_remove_message', 'yith_wcwl_no_product_to_remove_message_custom', 99 );

    Change “Product successfully removed” Text

    add_filter( 'yith_wcwl_product_removed_text', function() {
    	return 'Successfully removed.';
    } );

    Change Wishlist View Button Text

    You can modify that text by adding the following code in the functions.php file of your active child theme:

    if ( ! function_exists( 'yith_wcwl_view_wishlist_label_custom' ) ) {
        function yith_wcwl_view_wishlist_label_custom() {
            return 'your custom text';
        }
    }
    add_filter( 'yith_wcwl_view_wishlist_label', 'yith_wcwl_view_wishlist_label_custom', 99 );

    Get the Wishlist ID

    To obtain the user ID, you can utilize the filter “yith_wcwl_adding_to_wishlist_wishlist_id”. This filter can be modified according to your preferences.

    apply_filters( 'yith_wcwl_adding_to_wishlist_wishlist_id', $wishlist_id );
    

    Get The Wishlist User ID

    To obtain the user ID, you can utilize the filter “yith_wcwl_adding_to_wishlist_user_id”. This filter can be modified according to your preferences.

    $user_id = apply_filters( 'yith_wcwl_adding_to_wishlist_user_id', intval( $atts['user_id'] ) );
    

    Increase the Expiration time of your Guest Users’ Wishlists

    Unlike wishlists for registered users, wishlists for guest users have a limited duration due to the expiration time of their cookies.

    To extend the expiration time of wish lists for guest users, insert the following code into the functions.php file of your active child theme. You only need to adjust the value of the $seconds variable to your preferred duration.

    if ( ! function_exists( 'yith_wcwl_cookie_expiration_custom' ) ) {
        function yith_wcwl_cookie_expiration_custom() {
            $seconds = 60 * 60 * 24 * 30; // time in seconds
            return $seconds;
        }
        add_filter( 'yith_wcwl_cookie_expiration', 'yith_wcwl_cookie_expiration_custom' );
    }

    Add the Wishlist Page as an Endpoint

    In order to add the YITH WooCommerce Wishlist page as an endpoint, add the following code in your functions.php of your theme:

    if (!function_exists('yith_wcwl_add_endpoint_my_account')) {
            function yith_wcwl_add_endpoint_my_account($items)
            {
                $logout = $items['customer-logout'];
                unset($items['customer-logout']);
    
                // Insert your custom endpoint.
                $items['my-wishlist'] = 'My Wishlist';
    
                // Insert back the logout item.
                $items['customer-logout'] = $logout;
    
                return apply_filters('yith_wcwl_account_menu_item', $items);
            }
    
            add_filter('woocommerce_account_menu_items', 'yith_wcwl_add_endpoint_my_account');
        }
    
        if (!function_exists('yith_wcwl_add_wishlist_endpoint')) {
            function yith_wcwl_add_wishlist_endpoint()
            {
                echo do_shortcode('[yith_wcwl_wishlist]');
            }
    
            add_action('woocommerce_account_my-wishlist_endpoint', 'yith_wcwl_add_wishlist_endpoint');
        }
    
        if (!function_exists('yith_wcwl_add_endpoints')) {
    
            function yith_wcwl_add_endpoints()
            {
                add_rewrite_endpoint('my-wishlist', EP_ROOT | EP_PAGES);
            }
    
            add_action('init', 'yith_wcwl_add_endpoints');
        }

    Wishlist Page is not Displaying Any Products

    Some users encounter an issue when adding products to their wishlist. Although the alert confirms the successful addition of products, upon visiting the wishlist page, none of the products are displayed. Instead, a message indicates that no products have been added to the wishlist.

    add_filter( 'yith_wcwl_remove_hidden_products_via_query', '__return_false' );
    

    Disable Wishlist Table Mobile View

    Layout of the wishlist changes when going to the mobile view, so if you want to avoid this, you can add the following code inside the functions.php file of your active child theme:

    add_filter( 'yith_wcwl_is_wishlist_responsive', '__return_false' );
    

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    Scroll to Top