Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bappi-d-great/1449e0e5e0b3687ca176 to your computer and use it in GitHub Desktop.
Save bappi-d-great/1449e0e5e0b3687ca176 to your computer and use it in GitHub Desktop.
Provide MarketPress coupon based on Membership level
add_filter( 'mp_coupon_value', 'mp_coupon_value_cb', 10, 3 );
function mp_coupon_value_cb( $return, $code, $total ) {
$arr = array(
'XXX' => 1,
'YYY' => 2
);
if( current_user_on_level( $arr[$code] ) ){
return $return;
}else{
global $mp;
$currency = $mp->get_setting('currency', 'USD');
$symbol = $mp->currencies[$currency][1];
$symbols = explode(', ', $symbol);
if (is_array($symbols)) {
$symbol = "";
foreach ($symbols as $temp) {
$symbol .= '&#x'.$temp.';';
}
} else {
$symbol = '&#x'.$symbol.';';
}
$del = explode( $symbol, $return['discount'] );
$return['new_total'] = $return['new_total'] + $del[1];
$return['discount'] = 0;
return $return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment