Additional, optional fee on Woocommerce Checkout [closed]

Ok, so this is how i did it.

Create a product called Shipping Insurance which is $3, make sure its a hidden product(Catalog Visibility on the right side)

Use the following code in your theme’s functions.php file:

add_action('woocommerce_cart_totals_after_shipping', 'wc_shipping_insurance_note_after_cart');
function wc_shipping_insurance_note_after_cart() {
global $woocommerce;
    $product_id = 669;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
    $_product = $values['data'];
    if ( $_product->id == $product_id )
        $found = true;
    }
    // if product not found, add it
if ( ! $found ):
?>
    <tr class="shipping">
        <th><?php _e( 'Shipping Insurance', 'woocommerce' ); ?></th>
        <td><a href="https://wordpress.stackexchange.com/questions/121459/<?php echo do_shortcode("[add_to_cart_url id="669"]'); ?>"><?php _e( 'Add shipping insurance (+$3)' ); ?> </a></td>
    </tr>
<?php else: ?>
    <tr class="shipping">
        <th><?php _e( 'Shipping Insurance', 'woocommerce' ); ?></th>
        <td>$3</td>
    </tr>
<?php endif;
}

Change the $product_id variable to your product id that you created and when you’re on checkout, it will simply add this hidden product to your cart

Leave a Comment