Skip to content

Instantly share code, notes, and snippets.

@blivic
Last active March 18, 2019 12:46
Show Gist options
  • Save blivic/518b9b6fac57eb4f862eacbfdf32cb79 to your computer and use it in GitHub Desktop.
Save blivic/518b9b6fac57eb4f862eacbfdf32cb79 to your computer and use it in GitHub Desktop.
Show amount for 3, 6 and 12 installments (with percentage fee), under regular price
add_action( 'woocommerce_single_product_summary', 'mx_price_per_installments_w_fee', 11 );
function mx_price_per_installments_w_fee() {
global $product;
$price = $product->get_price();
$threeinstallments = 3;
$sixinstallments = 6;
$twelveinstallments = 12;
$fee = (3.5/100) * $price;
$price4installments = $price + $fee;
$price_per_threemonths = round ($price4installments / $threeinstallments, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN);
$price_per_sixmonths = round ($price4installments / $sixinstallments, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN);
$price_per_twelvemonths = round ($price4installments/ $twelveinstallments, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN);
echo "
<div id='installments-container'>
<div id='installments-text'>
Obročno plaćanje: 3 x <span>". $price_per_threemonths ." Kn</span> | 6 x <span>". $price_per_sixmonths ." Kn</span> | 12x <span>". $price_per_twelvemonths ." Kn</span>
</div>
</div>
";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment