本文介绍了Woocommerce具有来自functions.php的自定义定价的多种产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用以下代码更改了functions.php的价格.即使在购物车页面中,它也适用于单个产品.如何将代码用于具有不同定价的不同产品?那可能吗?

I have used the following code to change price from functions.php. It was working for a single product even in cart page also. How can i use the code for different products with different pricing? Is that possible?

团队"是一个分类法,"A团队","B团队"是术语.我将产品分配给"A团队"和"B团队".

'team' is a taxonomy and 'A-team', 'B-team' are the terms. I am assigning products to 'A-team' and 'B-team'.

例如:

对于"B团队":product_id 14 = $ 100,15 = $ 300,17 = $ 400;

For 'B-Team' : product_id 14 = $100, 15 = $300, 17 = $400;

原始价格:product_id 14 = $ 55,15 = $ 44,17 = $ 88;

Original Price : product_id 14 = $55, 15 = $44, 17 = $88;

在分类存档页面中:

如果"A-Team"归档产品应显示

If 'A-Team' archive products should show

[product_id 14 = $ 200、15 = $ 600、17 = $ 800;]

[product_id 14 = $200, 15 = $600, 17 = $800;]

如果"B-Team"归档产品应显示

If 'B-Team' archive products should show

[product_id 14 = $ 100,15 = $ 300,17 = $ 400;]

[product_id 14 = $100, 15 = $300, 17 = $400;]

我的代码:

function change_price($price, $productd){ 
   if($productd->id == 16): 
      return 160; 
   else: 
      return $price;
   endif;

add_filter('woocommerce_get_price','change_price', 10, 2);
add_filter('woocommerce_get_regular_price','change_price', 10, 2);
add_filter('woocommerce_get_sale_price','change_price', 10, 2);

提前谢谢.

推荐答案

我如下更改了我的代码.它为我工作.希望这对其他有问题的人有所帮助.

I have changed my code as follows. It's working for me. Hope this may helps for some other who have some problem.

`add_filter( 'woocommerce_get_price', function ($price, $productd ) { 
       if($team_id) :
          return get_post_meta($productd->id, 'tax_'.$team_id , true); 
       else:
          return $price;
       endif;

  }, 10, 2 );`

即使在添加到购物车"功能上也没有问题.

No problems even at 'Add-to-cart' functionality also.

谢谢,萨蒂亚(Satya)

Thanks,Satya

这篇关于Woocommerce具有来自functions.php的自定义定价的多种产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:39