Skip to content

Instantly share code, notes, and snippets.

@mtruitt
Created January 13, 2018 01:40
Show Gist options
  • Save mtruitt/3a59a89ed33886924a80581a4879b275 to your computer and use it in GitHub Desktop.
Save mtruitt/3a59a89ed33886924a80581a4879b275 to your computer and use it in GitHub Desktop.
Apply fee based on user role
<?php
function woo_add_cart_fee() {
global $woocommerce;
$current_user = wp_get_current_user();
if ( in_array( 'residential', $current_user->roles, true) ) {
$woocommerce->cart->add_fee( __( 'Custom', 'woocommerce' ), 5 );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment