【问题标题】:woocommerce wc_rbp_product_selling_price in custom data tag自定义数据标签中的 woocommerce wc_rbp_product_sales_price
【发布时间】:2020-04-26 04:28:43
【问题描述】:

在我正在使用 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;
}

怎么了?

【问题讨论】:

    标签: php html woocommerce hook-woocommerce


    【解决方案1】:

    我不是专家,但也许你应该减少优先级参数

    add_filter('wc_rbp_product_selling_price', 'custom_price', 99, 2 );

    它可能没有及时触发调整价格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      • 2018-09-21
      • 2011-01-12
      相关资源
      最近更新 更多