Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prozentuale Gebühr im WooCommerce Warenkorb
/**
* Prozentuale Gebühr im WooCommerce Warenkorb
*/
add_action( 'woocommerce_cart_calculate_fees', 'custom_fee_based_on_cart_total', 10, 1 );
function custom_fee_based_on_cart_total( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
// The percetage
$percent = 5; // 5%
// The cart total
$cart_total = $cart_object->cart_contents_total;
// The conditional Calculation
$fee = $cart_total >= 50 ? $cart_total * $percent / 100 : 0;
if ( $fee != 0 )
$cart_object->add_fee( __( "5 % Gebühr", "woocommerce" ), $fee, false );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment