• Resolved VinzClortho

    (@vinzclortho)


    Hi, is there a php conditional function to check on each page if there are products in wishlist? I would like to be able to change the icon I added to the navigation menu to show when there are products in wishlist.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Juan Coronel

    (@juaancmendez)

    Hi there,
    thanks for contacting us!

    To achieve what you need, you can use the following code by adding it in the functions.php file of your active theme:

    if ( class_exists( 'YITH_WCWL_Wishlist_Factory' ) && ! function_exists( 'yith_wcwl_woocommerce_before_main_content_custom' ) ) {
    function yith_wcwl_woocommerce_before_main_content_custom() {
    $jquery = '';
    $wishlist = YITH_WCWL_Wishlist_Factory::get_current_wishlist();
    if ( $wishlist && $wishlist->has_items() ) {
    $jquery = 'jQuery(document).ready(function($){
    /* insert your logic here */
    })';
    }
    wp_add_inline_script( 'jquery-yith-wcwl', $jquery );
    wp_add_inline_script( 'jquery-yith-wcwl-user', $jquery );
    }
    add_action( 'wp_enqueue_scripts', 'yith_wcwl_woocommerce_before_main_content_custom' );
    }

    Check it out and tell us any doubt, please.

    Best regards.

    Thread Starter VinzClortho

    (@vinzclortho)

    Hi, thanks a lot for your reply!

    YITH_WCWL_Wishlist_Factory::get_current_wishlist() was what I was looking for!

    I implemented the code a bit differently (without jquery):

    <?php if ( class_exists( 'YITH_WCWL_Wishlist_Factory' ) ) : 
    $notempty = "";
    $wishlist = YITH_WCWL_Wishlist_Factory::get_current_wishlist();
    if ( $wishlist && $wishlist->has_items() ) {
    $notempty = "notempty";
    }
    ?>
    <a class="<?php echo esc_attr($notempty) ?>" href=""></a>
    <?php endif; ?>

    Little else css does the rest of the work!

    It would be nice to be able to check this in ajax, otherwise the icon would change only after the page refresh. Is it possible to do this using the YITH WooCommerce Wishlist ajax class?

    Thanks

    Plugin Support Juan Coronel

    (@juaancmendez)

    Hi there.

    Unfortunately, that kind of customization is not possible at the moment.

    If you have any other questions, feel free to contact us.

    Best regards.

    Thread Starter VinzClortho

    (@vinzclortho)

    Ok, thanks for the reply.

    Best regards

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.