WooCommerce Cash On Delivery Extra Fee

WooCommerce cash on delivery is a feature that many e-commerce users need. E-commerce sites usually make the most sales with the option to cash on delivery. Normally you can choose to cash on delivery as a new shipping route from WooCommerce> Settings> Shipping. But this will cause confusion in most cases. Because credit card customers […]

WooCommerce Cash On Delivery

WooCommerce cash on delivery is a feature that many e-commerce users need. E-commerce sites usually make the most sales with the option to cash on delivery. Normally you can choose to cash on delivery as a new shipping route from WooCommerce> Settings> Shipping. But this will cause confusion in most cases. Because credit card customers may mistakenly choose cash on delivery as a shipping method.

In order to avoid this situation, I will try to explain how to add WooCommerce cash on delivery in this article. This method may cause you to interfere with your theme files. So if you don’t know what you are doing, please seek professional support.

How to Activate WooCommerce Cash on Delivery?

The first step is to activate the WooCommerce cash on delivery option. To do this, activate WordPress admin> WooCommerce> Settings> Payment> Cash on Delivery;

How to Add WooCommerce Cash on Delivery?

In the next step, we will add an extra fee for the cash on delivery option on our site. I added an extra $5 in this scenario. $ Fee = 5; You can edit the option according to yourself. Add this code to an available area of the View> Theme Editor> functions.php file. If you don’t know how to do this, use the Code Snippets plugin or get support from a WordPress expert.

add_action( 'woocommerce_cart_calculate_fees', 'custom_handling_fee', 10, 1 );
function custom_handling_fee ( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( 'cod' === WC()->session->get('chosen_payment_method') ) {
        $fee = 5;
        $cart->add_fee( 'Kapıda Ödeme Ekstra Ücret', $fee, true );
    }
}
add_action( 'wp_footer', 'custom_checkout_jqscript' );
function custom_checkout_jqscript() {
    if ( is_checkout() && ! is_wc_endpoint_url() ) :
    ?>
    <script type="text/javascript">
    jQuery( function($){
        $('form.checkout').on('change', 'input[name="payment_method"]', function(){
            $(document.body).trigger('update_checkout');
        });
    });
    </script>
    <?php
    endif;
}

After adding the code, the WooCommerce cash on delivery will be additionally reflected on the extra $5 fee payment page. After adding the code, the details on the payment form appear as follows;

You can send me any questions you have about the use of the code in the comments section. For more content like adding WooCommerce cash on delivery, visit my WooCommerce category.

Leave a Reply

Your email address will not be published. Required fields are marked *