从另一个WooCommerce插件获取自定义插件中的折扣价

时间:2016-05-25 07:00:01

标签: php wordpress wordpress-plugin woocommerce product

我为Wordpress / WooCommerce开发了一个自定义插件,基本上列出了产品的愿望清单。我无法解决的一件事是如何检索由其他插件添加的所有钩子/过滤器处理的价格:Woocommerce Role pricing (light)

我安装了Woocommerce Role pricing (light),我希望根据用户角色获得折扣价。因此,以编程方式在我正在构建的插件的上下文中获得折扣价。

通过WC_Product实例化产品仅适用于单一全价。

即:

$wooProduct = new WC_Product( $val->product_id );
$price = $wooProduct->get_price();
//^^ the above price is wrong and not discounted.

在我正在建设的背景下:

// Loop over products / Populate with quantity 0 if no quantity or entry found on existing product.
foreach ($products as $key => $val) {

    $wooProduct = new WC_Product( $val->product_id );

    $price = $wooProduct->get_price();
    //$price is wrong here and not discounted by role pricing light

    $name = $wooProduct->post->post_title;
    $id = $wooProduct->post->ID;
    $url = get_permalink ($id);

    $tmpProducts [] = array(
        "product_id"=>$val->product_id,
        "item_id"=> isset($userOrderProducts[$val->product_id]["item_id"]) ? $userOrderProducts[$val->product_id]["item_id"] : NULL,
        "title" => $wooProduct->post->post_title,
        "url" => get_permalink ($id),
        "price" => $wooProduct->get_price(),
        "qty" => isset($userOrderProducts[$val->product_id]["quantity"]) ? intVal($userOrderProducts[$val->product_id]["quantity"]) : 0,
    );
}

0 个答案:

没有答案