[英]woocommerce wc_rbp_product_selling_price in custom data tag
In a site that I am developing in woocommerce I needed to be able to create 6 price lists with fixed prices for each product and to be able to apply a global discount in percentage for the price list assigned to the customer.在我在 woocommerce 中开发的一个网站中,我需要能够为每个产品创建 6 个具有固定价格的价目表,并且能够为分配给客户的价目表应用全球折扣百分比。
For the 6 price lists i've managed it through the plugin "Role Based Price For WooCommerce"对于 6 个价目表,我通过插件“WooCommerce 基于角色的价格”进行管理
For the discount per client part i've created a little plugin.对于每个客户部分的折扣,我创建了一个小插件。 Here the code
这里的代码
function get_price_divider() {
$user_id = get_current_user_id();
$perc = get_user_meta( $user_id, 'sconto_cliente', true );
$sconto = ((int)$perc);
return $sconto;
}
add_filter('wc_rbp_product_selling_price', 'custom_price', 99, 2 );
function custom_price( $price, $product ) {
return ((int)$price)-((((int)$price)/100)*get_price_divider());
}
Everything works fine on the product page.在产品页面上一切正常。 It handle the hook 'wc_rbp_product_selling_price' correctly.
它正确处理钩子 'wc_rbp_product_ sell_price'。
However, I need to pass this price to another plugin with which I made the "tool finder" for the products on sale.但是,我需要将此价格传递给另一个插件,我使用该插件为销售产品制作了“工具查找器”。 The authors of the plugin (LSCF) give me the option to Create New Data Tag as specified here: https://pixolette.com/docs/lscf/custom-template/create-new-data-tag/
插件 (LSCF) 的作者为我提供了创建新数据标签的选项,如下所示: https : //pixolette.com/docs/lscf/custom-template/create-new-data-tag/
So i should display in their html template with this code所以我应该用这个代码在他们的 html 模板中显示
<div class="customdata">
Prezzo: {{post.custom_price}}
</div>
I've created the code below to do this but output always 0我已经创建了下面的代码来执行此操作,但输出始终为 0
add_action( 'lscf_custom_tags', 'lscf_custom_tags_function' );
function lscf_custom_tags_function( &$args ) {
global $price, $product;
$post_id = (int) $args['ID'];
$output = apply_filters( 'wc_rbp_product_selling_price', $price, $product );
$args['custom_price'] = $output;
}
What's wrong?怎么了?
I'm not an expert but maybe you should reduce priority argument in the我不是专家,但也许你应该减少优先级的争论
add_filter('wc_rbp_product_selling_price', 'custom_price', 99, 2 );
It probably doesn't fire in time to adjust the price.它可能不会及时调整价格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.