【问题标题】:How to display Total cost of products added in wishlist using yith woocommerce wishlist plugin?如何使用 yith woocommerce 愿望清单插件显示添加到愿望清单中的产品总成本?
【发布时间】:2017-01-17 12:59:54
【问题描述】:

我正在使用 Wordpress 和 Woocommerce 插件开发电子商务网站。 我已经安装了 Woocommerce 愿望清单插件供用户在愿望清单中添加产品,它是显示单位产品成本,添加到购物车按钮和产品图片。

我想显示添加到愿望清单中的总产品成本,以及添加到购物车按钮。请帮忙。

【问题讨论】:

    标签: wordpress woocommerce e-commerce


    【解决方案1】:

    要使用 YITH Woocommerce Wishlist 插件显示总产品成本,您可以使用 Jquery 执行此操作:

    var myArray = $(".wishlist_table .amount"); // Recover all product cost
    var result = 0;
    for (var i = 0; i<myArray.length; i++) {
        result += parseFloat(myArray[i].childNodes["0"].data); // Make the sum
    }
    
    $("#som").text(result); // Place total in a HTML element - my ID is "som" but no matter what it is
    
    $(".remove_from_wishlist").live('click', function(){ // When user remove item with AJAX         
        var href = $(this).attr('href'); // Find parent
        href = href.replace(/\D/g,'');  
        var arrayTo = $('#yith-wcwl-row-'+href+' .amount').text(); 
        arrayTo = parseFloat(arrayTo.replace(/\u20ac/g, '')); // u20ac is unicode character for euro sign but works with just 'D' instead
        var recoverTotal = $("#som").text(); // Recover the total
        var result2 = recoverTotal - arrayTo;
        $("#som").text(result2); // Display the final result
    });
    

    您必须将此代码放在简码函数中。它对我有用。

    【讨论】:

      【解决方案2】:

      我不确定您使用的是哪个愿望清单插件,因为有一些愿望清单插件。

      但是,我在使用YITH Woocommerce Wishlist plugin 时为此编写了一个解决方案。如果有帮助,请在此处分享该代码。

      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();
      
              if(isset($_REQUEST['add_all_to_cart'])){
                  $woocommerce->cart->add_to_cart($item['prod_id']);
              }
          }
          $output = 'Total Price: '.$product_price;
          $output .= "<a href='?add_all_to_cart'>Add All to Cart</a>";
          return $output;
      }
      add_shortcode( 'tnc-wishlist-summary', 'tnc_wishlist_summary_cart' );
      

      将此代码放在functions.php或独立插件中,并将以下短代码放在愿望清单页面上。

      [tnc-wishlist-summary]
      

      它将输出总价和将所有商品添加到购物车的链接。虽然没有风格。您需要根据自己的需要对其进行样式设置。

      谢谢

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多