Skip to content

Instantly share code, notes, and snippets.

@cklosowski
Last active October 31, 2016 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cklosowski/97c6513637bc55704f9f825b32904fd5 to your computer and use it in GitHub Desktop.
Save cklosowski/97c6513637bc55704f9f825b32904fd5 to your computer and use it in GitHub Desktop.
Add/Remove a fee based off cart existing in EDD
<?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