Last active
October 31, 2016 13:44
-
-
Save cklosowski/97c6513637bc55704f9f825b32904fd5 to your computer and use it in GitHub Desktop.
Add/Remove a fee based off cart existing in EDD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ck_add_remove_service_fee() { | |
if ( ! class_exists( 'Easy_Digital_Downloads' ) ) { | |
return; | |
} | |
$has_fee = EDD()->fees->get_fee( 'service-fee' ); | |
$items = edd_get_cart_quantity(); | |
if ( ! empty( $items ) && ! $has_fee ) { | |
$args = array( | |
'amount' => 3, | |
'label' => 'Service Fee', | |
'id' => 'service-fee', | |
'type' => 'fee', | |
'no_tax' => false, | |
); | |
EDD()->fees->add_fee( $args ); | |
} elseif ( empty( $items ) && $has_fee ) { | |
EDD()->fees->remove_fee( 'service-fee' ); | |
} | |
} | |
add_action( 'init', 'ck_add_remove_service_fee', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment