Advertisement
designbymerovingi

custom buyCRED exchange rate

May 16th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. /**
  2.  * Adjust buyCRED Cost
  3.  * @version 1.0
  4.  */
  5. add_filter( 'mycred_buycred_get_cost', 'mycred_pro_adjust_buycred_cost', 10, 3 );
  6. function mycred_pro_adjust_buycred_cost( $cost, $amount, $type ) {
  7.  
  8.     // Get our custom exchange rate (defaults to 1)
  9.     $rate = get_option( 'buycred_exchange_rate', 1 );
  10.  
  11.     // Calculate cost based on the amount the user selected to purchase
  12.     // Note that most payment gateways (not all) requires the cost to be
  13.     // formated using two decimal places.
  14.     $cost = number_format( ( $amount * $rate ), 2, '.', '' );
  15.  
  16.     return $cost;
  17.  
  18. }
  19.  
  20. /**
  21.  * Setup Cron
  22.  * @version 1.0
  23.  */
  24. add_action( 'init', 'mycred_pro_buycred_rate_cron' );
  25. function mycred_pro_buycred_rate_cron() {
  26.  
  27.     if ( ! wp_next_scheduled( 'buycred_custom_rate' ) )
  28.         wp_schedule_event( time(), 'hourly', 'buycred_custom_rate' );
  29.  
  30.     add_action( 'buycred_custom_rate', 'mycred_pro_change_rate_cron_task' );
  31.  
  32. }
  33.  
  34. /**
  35.  * The Cron Task
  36.  * @version 1.0
  37.  */
  38. function mycred_pro_change_rate_cron_task() {
  39.  
  40.     // Get current reate
  41.     $rate = get_option( 'buycred_exchange_rate', 1 );
  42.  
  43.     // Update your rate in any way or form
  44.  
  45.     // Save new rate
  46.     update_option( 'buycred_exchange_rate', $rate );
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement