I'm a bit new to wordpress and would like to have some advise. I try to add a optional field to the card which rounds the card total. I would like that it doesnt round the card total when it isnt checked.. So this is my current situation and i used this code for it:
@functios.php
function woo_add_cart_fee() {
global $woocommerce;
$totalprice = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_total() ) );
$rounded = ceil($totalprice);
$donation = $rounded-$totalprice;
$woocommerce->cart->add_fee( __('Donatie', 'woocommerce'),$donation);
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
and this @cart-totals.php
<?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
<tr class="fee">
<th><input type="checkbox"><?php echo esc_html( $fee->name ); ?></th>
<td data-title="<?php echo esc_html( $fee->name ); ?>"><?php wc_cart_totals_fee_html( $fee ); ?></td>
</tr>
<?php endforeach; ?>
So who can tell me where I can add some function that will only rounds my cart total when the donation option is checked?
Aucun commentaire:
Enregistrer un commentaire