Skip to content

Instantly share code, notes, and snippets.

@growdev
Created September 10, 2015 21:38
Show Gist options
  • Save growdev/5a6c2582807fcf4575ac to your computer and use it in GitHub Desktop.
Save growdev/5a6c2582807fcf4575ac to your computer and use it in GitHub Desktop.
Get Product Discounted Price
<?php
// add qty to cart to trigger dynamic pricing
$cart_item_key = WC()->cart->add_to_cart('8','300');
$product = wc_get_product( '8' );
echo "NAME: " . $product->get_title() . "\n";
$price = $product->get_price();
echo "PRICE: " . $price . "\n";
/*
Currently this is output:
NAME: Dinosaur Shirt
PRICE: 10
Expecting price to drop to 4.5
*/
// remove qty from cart
WC()->cart->remove_cart_item( $cart_item_key );
@growdev
Copy link
Author

growdev commented Sep 11, 2015

@lucasstark
It's a simple product with some quantity price changes:
screen shot 2015-09-11 at 3 59 17 pm

I'm not sure if that's an advanced or simple rule.

I think i see what your asking, for a function that you can manually pass a different quantity to to get what the discount would be at that amount?

Yes, exactly that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment