Oxygen Builder Wishlist Counter Product Woocommerce

This will outline [yith_wcwl_items_count] shortcode in your site; area it anywhere you desire your counter to appear, and the plugin will do the rest Shortcode will be changed with present day objects count; besides, if consumer provides or eliminates something from wishlist, depend will be mechanically up to date by means of AJAX

1 Step install WordPress Plugin Using YITH WooCommerce Wishlist

2 Add Custom Code snippet Plugin I am Using Advanced Scripts Plugin


<?php

// Your PHP code goes here!
if ( defined( 'YITH_WCWL' ) && ! function_exists( 'yith_wcwl_get_items_count' ) ) {
  function yith_wcwl_get_items_count() {
    ob_start();
    ?>
    <p class="yith-wcwl-icon"><?php echo esc_html( yith_wcwl_count_all_products() ); ?></p>
    <?php
    return ob_get_clean();
  }

  add_shortcode( 'yith_wcwl_items_count', 'yith_wcwl_get_items_count' );
}

if ( defined( 'YITH_WCWL' ) && ! function_exists( 'yith_wcwl_ajax_update_count' ) ) {
  function yith_wcwl_ajax_update_count() {
    wp_send_json( array(
      'count' => yith_wcwl_count_all_products()
    ) );
  }

  add_action( 'wp_ajax_yith_wcwl_update_wishlist_count', 'yith_wcwl_ajax_update_count' );
  add_action( 'wp_ajax_nopriv_yith_wcwl_update_wishlist_count', 'yith_wcwl_ajax_update_count' );
}

if ( defined( 'YITH_WCWL' ) && ! function_exists( 'yith_wcwl_enqueue_custom_script' ) ) {
  function yith_wcwl_enqueue_custom_script() {
    wp_add_inline_script(
      'jquery-yith-wcwl',
      "
        jQuery( function( $ ) {
          $( document ).on( 'added_to_wishlist removed_from_wishlist', function() {
            $.get( yith_wcwl_l10n.ajax_url, {
              action: 'yith_wcwl_update_wishlist_count'
            }, function( data ) {
              $('.yith-wcwl-items-count').children('i').html( data.count );
            } );
          } );
        } );
      "
    );
  }

  add_action( 'wp_enqueue_scripts', 'yith_wcwl_enqueue_custom_script', 20 );
}

3 Step Where you Want Show The Wishtlist Like Header Main Template Shortcode [yith_wcwl_items_count]


Comments

Leave a Reply

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