Skip to content

Instantly share code, notes, and snippets.

@lucasstark
Created September 24, 2013 17:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasstark/6687811 to your computer and use it in GitHub Desktop.
Save lucasstark/6687811 to your computer and use it in GitHub Desktop.
$amount = apply_filters('woocommerce_dynamic_pricing_get_rule_amount', $rule['amount'], $rule, $cart_item, $this);
switch ($rule['type']) {
case 'price_discount':
$adjusted = floatval($price) - floatval($amount);
$result = $adjusted >= 0 ? $adjusted : 0;
break;
case 'percentage_discount':
if ($amount > 1) {
$rule['amount'] = $amount / 100;
}
$result = round(floatval($price) - ( floatval($amount) * $price), (int) get_option('woocommerce_price_num_decimals'));
break;
case 'fixed_price':
$result = round($amount, (int) get_option('woocommerce_price_num_decimals'));
break;
default:
$result = false;
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment