Guest User

Untitled

a guest
Jan 20th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. <?php
  2.  
  3. function edd_currency_csmz_price_format($newpriceformat, $price, $currency, $formatted){
  4.  
  5. global $edd_options, $post, $edd_currency_public, $edd_currency_model;
  6.  
  7. if(!empty($post) && $post->post_type == 'download') {
  8. // If replace currency code
  9. if( isset($edd_options['replace_currency_code']) && $edd_options['replace_currency_code'] == '1' ) {
  10.  
  11. // Getting main plugin currency position
  12. if( isset($edd_options['currency_position']) && $edd_options['currency_position'] == 'before' ) {
  13. $newpriceformat = '<span class="currency-symbol">'.$currency.'</span> <span class="currency-amount">'.$price.'</span>';
  14. } else {
  15. $newpriceformat = '<span class="currency-amount">'.$price.'</span> <span class="currency-symbol">'.$currency.'</span>';
  16. }
  17.  
  18. } elseif( isset( $edd_options['append_code'] ) && $edd_options['append_code'] == '1' ) { //Check Append Currency Code settings is checked
  19.  
  20. //check append currency code is before
  21. if( isset( $edd_options['curr_code_position'] ) && $edd_options['curr_code_position'] == 'before' ) {
  22. $newpriceformat = '<span class="currency-symbol">'.$currency.'</span> <span class="currency-amount">'.$newpriceformat.'</span>';
  23. } else {
  24. $newpriceformat = '<span class="currency-amount">'.$newpriceformat.'</span> <span class="currency-amount">'.$currency.'</span>';
  25. }
  26.  
  27. } //end if to check append code is enabled or not
  28. }
  29.  
  30. return $newpriceformat;
  31. }
  32.  
  33. add_filter('edd_currency_price_format', 'edd_currency_csmz_price_format', 10, 4);
  34.  
  35. function edd_currency_csmz_change_before_format($new_formatted, $formatted, $currency, $price){
  36.  
  37. global $edd_options, $post, $edd_currency_public, $edd_currency_model;
  38.  
  39. if(!empty($post) && $post->post_type == 'download') {
  40.  
  41. $stored_currency = edd_currency_get_stored_currency(); // get cookie currency
  42. $exchange_rates = edd_currency_get_exchange_rates();
  43.  
  44. $cur_symbol = edd_currency_get_symbol( $currency ) ;
  45. $new_formatted = $edd_currency_public->edd_currency_append_code( $cur_symbol, $price, $currency, $formatted );
  46.  
  47. if( !empty( $price ) && $stored_currency != $currency && $edd_currency_model->edd_currency_check_open_exchange() && isset( $exchange_rates[$stored_currency] ) ) {
  48.  
  49. // check if cookie curreny is not the same as base currency and open change rate is setup properly and custom rate is set for stored currency
  50. $new_symbol = edd_currency_get_symbol( $stored_currency );
  51. $new_price = edd_currency_get_converted_price( $price );
  52. $new_price_formt = $new_symbol.$new_price;
  53. $new_changed_format = $edd_currency_public->edd_currency_append_code( $new_symbol, $new_price, $stored_currency, $new_price_formt );
  54.  
  55. if( isset( $edd_options['replace_base_currency'] ) && $edd_options['replace_base_currency'] == '1' ) {
  56.  
  57. $new_formatted = $new_changed_format;
  58.  
  59. } else {
  60.  
  61. $new_formatted .= ' <span class="main-wrap">( ' . $new_changed_format . ' )</span> ' ;
  62.  
  63. }
  64. }
  65. }
  66.  
  67. return $new_formatted;
  68. }
  69.  
  70. add_filter('edd_currency_change_before_format', 'edd_currency_csmz_change_before_format', 10, 4);
  71.  
  72. function edd_currency_csmz_change_after_format($new_formatted, $formatted, $currency, $price){
  73.  
  74. global $edd_options, $post, $edd_currency_public, $edd_currency_model;
  75.  
  76. if(!empty($post) && $post->post_type == 'download') {
  77.  
  78. $stored_currency = edd_currency_get_stored_currency();
  79. $exchange_rates = edd_currency_get_exchange_rates();
  80. $cur_symbol = edd_currency_get_symbol( $currency ) ;
  81. $new_formatted = $edd_currency_public->edd_currency_append_code( $cur_symbol, $price, $currency, $formatted );
  82.  
  83. //Check Our Cookie is set
  84. if( !empty( $price ) && $stored_currency != $currency && $edd_currency_model->edd_currency_check_open_exchange() && isset( $exchange_rates[$stored_currency] ) ) {
  85.  
  86. $new_symbol = edd_currency_get_symbol( $stored_currency );
  87. $new_price = edd_currency_get_converted_price( $price );
  88.  
  89. // only 1 line change , we can make this functions ( edd_currency_change_after_format and edd_currency_change_before_format) common in future
  90. $new_price_formt = $new_price.$new_symbol;
  91. $new_changed_format = $edd_currency_public->edd_currency_append_code( $new_symbol, $new_price, $stored_currency, $new_price_formt );
  92.  
  93. //Check Replace Base Currency settings is checked
  94. if( isset( $edd_options['replace_base_currency'] ) && $edd_options['replace_base_currency'] == '1' ) {
  95.  
  96. $new_formatted = $new_changed_format;
  97.  
  98. } else {
  99.  
  100. $new_formatted .= ' <span class="main-wrap">( ' . $new_changed_format . ' )</span> ';
  101. }
  102. }
  103. }
  104. return $new_formatted;
  105. }
  106.  
  107. add_filter('edd_currency_change_after_format', 'edd_currency_csmz_change_after_format', 10, 4);
Add Comment
Please, Sign In to add comment