Skip to content

Instantly share code, notes, and snippets.

@TravisBallard
Created February 12, 2013 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TravisBallard/4770528 to your computer and use it in GitHub Desktop.
Save TravisBallard/4770528 to your computer and use it in GitHub Desktop.
Causes 500 Internal Server Error after saving a page and clicking 'view page' in the updated notice.
<?php
/**
* add discount to logged in users based on available capabilities
*
* @param mixed $cart
*/
function vpm_apply_discount( $cart )
{
if( ! is_user_logged_in() ){
$cart->remove_coupons();
return;
}
if( current_user_can( 'view_gold' ) ){
if( ! $cart->has_discount( 'VPMGOLD20' ) ){
$cart->add_discount( 'VPMGOLD20' );
}
}
if( current_user_can( 'view_silver' ) ){
if( ! $cart->has_discount( 'VPMSILVER15' ) ){
$cart->add_discount( 'VPMSILVER15' );
}
}
if( current_user_can( 'view_bronze' ) ){
if( ! $cart->has_discount( 'VPMBRONZE10' ) ){
$cart->add_discount( 'VPMBRONZE10' );
}
}
}
add_action('woocommerce_before_calculate_totals', 'vpm_apply_discount' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment