2015-12-10 29 views
0

我需要改变woocommerce的工作方式,以便以标准方式获得产品价格,而不是通过API提供给我的价格。Woocommerce从哪里获得产品价格?

为此,我需要知道获取定价数据的代码/函数的位置。

这是因为公司有一个离线系统,它将连接到在线系统以实时提供价格(因为公司有5种不同的价格,每种产品都取决于客户,这些价格都存储在离线数据库)。

+0

好像使用[WooCommerce API]的绝好机会(https://woothemes.github.io/woocommerce-rest-api-docs/) – helgatheviking

回答

1

基本价格是简单地张贴元

$price = get_post_meta(get_the_ID(), '_regular_price', true); 

销售价格,仅仅是一个不同的元关键。我认为它是:

$sale = get_post_meta(get_the_ID(), '_sale_price', true); 

您还可以使用

get_sale_price() //returns the product's sale price. 

get_regular_price() //Returns the product's regular price. 
1

价格挂钩

使用woocommerce_get_price钩来回报您的自定义价格值。

add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);

检查被注射作为可调用功能的第二依赖产品对象。

function return_custom_price($price, $prod_obj) {

+0

首先,感谢帮助。所以我采纳了你的建议,并发现: 'function return_custom_price($ price,$ product){ global $ post,$ blog_id; $ price = get_post_meta($ post-> ID,'_regular_price'); $ post_id = $ post-> ID; $ price =($ price [0] * 2.5); return $ price; } 的add_filter(“woocommerce_get_price”,“return_custom_price”,10,2);' 这适用于产品和类别页面,但是当加入到篮它返回0价与错误:未定义偏移量:0 此外,它生成一个尝试获取非对象错误的属性,这似乎与$ post-> ID部分有关 – mevukpaul