I would like you to ask, how can I add custom html for fee I am adding dynamically to the order?
I am doing this way:
add_action( 'woocommerce_cart_calculate_fees', 'apply_discount_for_subscribers', 20, 1 );
function apply_discount_for_subscribers( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
if ( is_user_logged_in() ) {
$list_id = 3; // ID
// Sprawdzenie subskrypcji
$subscription_status = check_subscription_status( $list_id );
if ( $subscription_status === 'subscribed' ) {
$label = '5% discount:';
$discount = $cart->get_subtotal() * 0.05; // 5% zniżki
$cart->add_fee( $label, -$discount, true, 'standard' );
}
}
}
But what I receive is:
5% rabatu dla subskrybentów:
<span class="woocommerce-Price-amount amount">
<bdi>-12,50
<span class="woocommerce-Price-currencySymbol">zł</span>
</bdi>
</span>
Basically it would be enough to just wrap this in div, but I cannot not achieve it:
<div>
5% rabatu dla subskrybentów:
<span class="woocommerce-Price-amount amount">
<bdi>-12,50
<span class="woocommerce-Price-currencySymbol">zł</span>
</bdi>
</span>
</div>
BTW. why add_fee does not display as defined in review-order.php
<?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
<tr class="fee">
<th><?php echo esc_html( $fee->name ); ?></th>
<td><?php wc_cart_totals_fee_html( $fee ); ?></td>
</tr>
<?php endforeach; ?>
Please help! :)
You can wrap div like
$label = '<div>5% discount:</div>';but as you can see inWC()->cart->get_fees()loop label code useesc_htmlso it will not work.So You can override the
review-order.phptemplate file in your theme. follow the below steps.woocommerce.woocommercefolder, create another folder calledcheckout.review-order.phpfile from thewp-content/plugins/woocommerce/templates/checkoutdirectory to your newly createdwoocommerce/checkoutfolder within your theme.review-order.phpfile.Change this code
to this and add a condition based on your fee label so it only applies to that particular fee
5% discount:unless you don't want to apply for all fees.