Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('woocommerce_cart_calculate_fees', 'dnd_add_custom_fees', 999, 1);
- function dnd_add_custom_fees($cart) {
- if (is_admin() || defined('DOING_AJAX')) {
- return;
- }
- $label = get_option('drag_n_drop_cart_fee_label', 'Custom Fee');
- $amount = 0;
- // Debug logging to check if this function is triggered
- error_log('Running dnd_add_custom_fees');
- $file_uploads = wp_list_pluck($cart->get_cart_contents(), 'dnd-wc-file-upload');
- if ($file_uploads && is_array($file_uploads)) {
- foreach ($file_uploads as $files) {
- if ($files && is_array($files) && count($files) > 0) {
- $amount += 8.85;
- }
- }
- }
- if ($amount > 0) {
- foreach ($cart->get_fees() as $key => $fee) {
- if ($fee->name === $label) {
- unset($cart->get_fees()[$key]);
- }
- }
- // Debug logging to confirm the fee amount
- error_log("Adding fee of amount: $amount");
- $cart->add_fee($label, $amount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement