mercredi 25 mai 2016

Woocommerce - Get discounted price within custom plugin from another woocommerce plugin

I've developed a custom plugin for wordpress / woocommerce that is essentially listing out a wishlist of products. One thing I can't work out is how to retrieve the price processed by all hooks / filters added by other plugins(Woocommerce Role pricing light).

I have role pricing light installed and would like to get the discounted price based on the user role. So programmatically get the discounted price in the context of the plugin I'm building..

Instantiating the product via WC_Product works for the single full price only.

ie:

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

In context of what I'm building:

    // 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,
        );
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire