php - 自定义数据标签中的 woocommerce wc_rbp_product_sales_price
问题描述
在我正在开发的 woocommerce 网站中,我需要能够为每种产品创建 6 个具有固定价格的价目表,并能够为分配给客户的价目表应用全球折扣百分比。
对于 6 个价目表,我通过插件“WooCommerce 的基于角色的价格”进行了管理
对于每个客户部分的折扣,我创建了一个小插件。这里的代码
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());
}
在产品页面上一切正常。它正确处理钩子'wc_rbp_product_sales_price'。
但是,我需要将此价格传递给另一个插件,我用它为销售的产品制作了“工具查找器”。插件 (LSCF) 的作者为我提供了创建新数据标签的选项,如下所示:https ://pixolette.com/docs/lscf/custom-template/create-new-data-tag/
所以我应该用这段代码在他们的 html 模板中显示
<div class="customdata">
Prezzo: {{post.custom_price}}
</div>
我创建了下面的代码来执行此操作,但输出始终为 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;
}
怎么了?
解决方案
我不是专家,但也许您应该减少
add_filter('wc_rbp_product_selling_price', 'custom_price', 99, 2 );
它可能不会及时调整价格。
推荐阅读
- android - 当从活动发送数据到广播接收器时,应用程序在 startActivity 上崩溃
- c# - 在 Windows 上使用 WiFi Direct Api?
- angular - 无法在选项中选择值(角度下拉列表。)
- arrays - 如何评估这个 Kotlin 函数来转换 Any 的 ArrayList?到 Double 的 ArrayList
- json - karate : 在请求 JSON 中发送布尔值作为参数
- c# - 如何每次生成相同的 Guid?
- shopify - 生成混合产品和博客文章部分 Shopify
- c++ - QFileDialog:windows下文件夹名出现两次
- angular - 自定义表单控件中具有无效值的 writeValue
- xml - XSLT 返回原子值