Support » Plugin: YITH WooCommerce Wishlist » Total cost of products added in wishlist

  • Resolved angeloarlotta


    I found this function that I put in function.php:

    function tnc_wishlist_summary_cart(){
        global $woocommerce;
        $wl_items = YITH_WCWL()->get_products();
        $product_price = 0;
        foreach ($wl_items as $key => $item) {
            $the_product = wc_get_product($item['prod_id']);
            $product_price += $the_product->get_price();
        $output = 'Total Price: '.$product_price;
        return $output;
    add_shortcode( 'tnc-wishlist-summary', 'tnc_wishlist_summary_cart' );

    Then I call this function with a shortcode [tnc-wishlist-summary] but it seems returning always a 0 count.

    What I am missing?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author YITHEMES


    Hi there

    this code seems very old, and surely was created with a version of the plugin older than 3.x
    I suggest you to replace it with this code that I created for you

    if ( ! function_exists( 'yith_wcwl_wishlist_cost_summary' ) ) {
    	function yith_wcwl_wishlist_cost_summary() {
    		$default_wishlist = yith_wcwl_get_wishlist( false );
    		$total_price      = 0;
    		if ( $default_wishlist->has_items() ) {
    			foreach ( $default_wishlist->get_items() as $item ) {
    				$total_price += $item->get_product_price();
    		$output = 'Total Price: ' . wc_price( $total_price );
    		return $output;
    add_shortcode( 'yith_wcwl_wishlist_cost_summary', 'yith_wcwl_wishlist_cost_summary' );

    It defines a shortcode too ([yith_wcwl_wishlist_cost_summary]) and should print the correct summary cost

    Thread Starter angeloarlotta


    Hi @yithemes and really thank you for helping with that feature!
    It works perfectly, really appreciated!


    Plugin Author YITHEMES


    You’re welcome!
    If you enjoy our plugin, don’t forget to leave us a 5 star review, to support us and help our work
    Thank you!

    Hi there!

    Is there a way to add the amounts? Because it only adds the unit values, without considering the quantities of each item.

    Sorry for my English

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Total cost of products added in wishlist’ is closed to new replies.