WooCommerce - Conditional check box and fee

I know only a little bit of PHP and am stuck on this. I am customizing a WP site running Woocommerce. I have added some snippets that I found on the internet to add a check box to the checkout page. I need it to charge a fee when the check-box is marked. So basically, customers can add a card to their order for 0.75. They check the box if they want the card, and the fee needs to then be added to the cart. I have the boxes showing up, but can’t get the fee to add to the cart. Can someone help me?

This is working to add the extra fields to checkout:

add_action('woocommerce_after_order_notes', 'gift_wrapping_field');

function gift_wrapping_field( $checkout ) 

woocommerce_form_field( 'gift_wrapping', array(
    'type'          => 'checkbox',
    'class'         => array('input-checkbox'),
    'label'         => __(' Include a card for the recipient of my gift purchase (additional $0.75) '),
    'required'        => false,
    ), $checkout->get_value( 'gift_wrapping' ));
woocommerce_form_field( 'gift_card_name', array(
    'type'          => 'text',
    'class'         => array('gift-card-text'),
    'label'         => __(' Name of recipient: '),
    'required'        => false,
    ), $checkout->get_value( 'gift_card_name' ));

This is the code I am using to try to have the fee in the cart when the check box is selected, but its not working (adapted from here:http://www.remicorson.com/add-custom-fee-to-woocommerce-cart-dynamically/):

 * WooCommerce Extra Feature
 * --------------------------
 * Add custom fee to cart automatically
function woo_add_cart_fee() {
  global $woocommerce;
  if( get_option('gift_wrapping') == 'value' ) { $woocommerce->cart->add_fee( __('Gift Card', 'woocommerce'), 0.75 );
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );

Could someone kindly explain to me how to get this working properly? Thank you!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.