daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Jan 20th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. add_action('admin_menu', 'jtd_vat_settings_menu');
  3. function jtd_vat_settings_menu() {
  4.   add_submenu_page('edit.php?post_type=foxyshop_product', __('VAT Display', 'foxyshop'), __('VAT Display', 'foxyshop'), apply_filters('foxyshop_settings_perm', 'manage_options'), 'foxyshop_vat_display', 'foxyshop_vat_display');
  5. }
  6. function foxyshop_vat_display() {
  7.   global $foxyshop_settings, $foxycart_version_array;
  8.   if (!defined('FOXYSHOP_TEMPLATE_PATH')) define('FOXYSHOP_TEMPLATE_PATH',STYLESHEETPATH);
  9.  
  10.   if (isset($_GET['saved'])) echo '<div class="updated"><p>' . __('Your Settings Have Been Saved.', 'foxyshop') . '</p></div>';
  11. ?>
  12. <div id="foxyshop_settings_wrap" class="wrap">
  13.  
  14.   <div class="icon32" id="icon-options-general"><br></div>
  15.   <h2>FoxyShop VAT Settings</h2>
  16.  
  17.   <form method="post" name="foxycart_vat_settings_form" action="options.php" style="margin-top: 14px;">
  18.  
  19.     <table class="widefat">
  20.       <thead>
  21.         <tr>
  22.           <th><?php _e('FoxyCart VAT Display Settings', 'foxyshop'); ?></th>
  23.         </tr>
  24.       </thead>
  25.       <tbody>
  26.         <tr>
  27.           <td>
  28.             <label for="foxyshop_display_vat"><?php echo __('Enable FoxyCart VAT Display', 'foxyshop'); ?></label>
  29.             <select name="foxyshop_display_vat" id="foxyshop_display_vat">
  30.               <?php
  31.               $vat_options = array(
  32.                 'on' => 'Enable FoxyCart VAT Display',
  33.                 'off' => 'Disable FoxyCart VAT Display',
  34.                 'both' => 'Show price with and without FoxyCart VAT'
  35.               );
  36.               foreach ( $vat_options as $key => $val) {
  37.                 echo '<option value="' . $key . '"' . ($foxyshop_settings['display_vat'] == $key ? ' selected="selected"' : '') . '>' . $val . '  </option>'."\n";
  38.               } ?>
  39.             </select>
  40.           </td>
  41.         </tr>
  42.         <tr>
  43.           <td>
  44.             <label for="foxyshop_vat_rate"><?php echo __('VAT Rate', 'foxyshop'); ?></label>
  45.             <input type="text" name="foxyshop_vat_rate" id="foxyshop_vat_rate" value="<?php echo esc_attr($foxyshop_settings['vat_rate']); ?>" />
  46.             <a href="#" class="foxyshophelp">Please enter a decimal. e.g. 0.2 = 20%, or .05 = 5%</a>
  47.           </td>
  48.         </tr>
  49.       </tbody>
  50.     </table>
  51.  
  52.     <input type="hidden" name="foxyshop_vat_settings_update" value="1" />
  53.     <?php wp_nonce_field('update-foxyshop-vat-options'); ?>
  54.  
  55.     <p><input type="submit" class="button-primary" value="<?php _e('Save All Settings', 'foxyshop'); ?>" /></p>
  56.  
  57.   </form>
  58.  
  59.   <script>
  60.     jQuery(document).ready(function($) {
  61.  
  62.       //Tooltip
  63.       xOffset = -10;
  64.       yOffset = 10;
  65.       $("a.foxyshophelp").hover(function(e) {
  66.         var tooltip_text = $(this).html();
  67.         $("body").append("<p id='tooltip'>"+ tooltip_text +"</p>");
  68.         $("#tooltip")
  69.           .css("top",(e.pageY - xOffset) + "px")
  70.           .css("left",(e.pageX + yOffset) + "px")
  71.           .fadeIn("fast");
  72.       }, function(){
  73.         $("#tooltip").remove();
  74.       }).mousemove(function(e){
  75.         $("#tooltip")
  76.           .css("top",(e.pageY - xOffset) + "px")
  77.           .css("left",(e.pageX + yOffset) + "px");
  78.       }).click(function(e) {
  79.         e.preventDefault();
  80.         return false;
  81.       }).attr("tabindex", "99999");
  82.  
  83.     });
  84.   </script>
  85.  
  86. </div>
  87.  
  88. <?php
  89.  
  90. }
  91.  
  92.  
  93.  
  94. add_action('admin_init', 'jtd_save_vat_display_settings');
  95. function jtd_save_vat_display_settings() {
  96.   if (!isset($_POST['foxyshop_vat_settings_update'])) return;
  97.   if (!check_admin_referer('update-foxyshop-vat-options')) return;
  98.   global $foxyshop_settings;
  99.  
  100.   if ( in_array( $_POST['foxyshop_display_vat'], array('on', 'off', 'both') ) ) {
  101.     $foxyshop_settings['display_vat'] = $_POST['foxyshop_display_vat'];
  102.   }
  103.  
  104.   if ( is_numeric( $_POST['foxyshop_vat_rate'] ) ) {
  105.     $foxyshop_settings['vat_rate'] = $_POST['foxyshop_vat_rate'];
  106.   }
  107.  
  108.  
  109.   update_option("foxyshop_settings", $foxyshop_settings);
  110.   wp_redirect("edit.php?post_type=foxyshop_product&page=foxyshop_vat_display&saved=1");
  111.   exit;
  112. }
  113.  
  114.  
  115. function jtd_price($skip_sale_price = false, $echo_output = true) {
  116.   global $product, $foxyshop_settings;
  117.  
  118.  
  119.   $vat_display = $foxyshop_settings['display_vat'];
  120.   $vat_rate = $foxyshop_settings['vat_rate'];
  121.  
  122.   $no_vat_price = number_format((double)get_post_meta($product['id'],'_price', 1),FOXYSHOP_DECIMAL_PLACES,".","");
  123.   $no_vat_sale_price = number_format((double)get_post_meta($product['id'],'_saleprice', 1),FOXYSHOP_DECIMAL_PLACES,".","");
  124.  
  125.   if ( $vat_display == 'on' || $vat_display == 'both' ) {
  126.     $vat_price = ( $no_vat_price * $vat_rate ) + $no_vat_price;
  127.     $vat_sale_price = ( $no_vat_sale_price * $vat_rate ) + $no_vat_sale_price;
  128.   }
  129.  
  130.  
  131.   $write = '<div class="foxyshop_price">';
  132.  
  133.   if ($product['price'] == $product['originalprice']) {
  134.  
  135.     if ( $vat_display == 'on' || $vat_display == 'both' ) {
  136.       $write .= '<span class="">' . foxyshop_currency($vat_price) . '</span>';
  137.       $write .= ' <small style="font-size:11px;color:grey;">price includes VAT</small>';
  138.     } else {
  139.       $write .= '<span class="">' . foxyshop_currency($no_vat_price) . '</span>';
  140.     }
  141.     if ( $vat_display == 'both' ) {
  142.       $write .= '<br><span class="foxyshop_currentprice_no_vat">' . foxyshop_currency($no_vat_price) . '</span>';
  143.       $write .= ' <small style="font-size:11px;color:grey;">price excluding VAT</small>';
  144.     }
  145.  
  146.  
  147.   } else {
  148.  
  149.  
  150.     if (!$skip_sale_price) {
  151.       if ( $vat_display == 'on' || $vat_display == 'both' ) {
  152.         $write .= '<del class="old1">' . foxyshop_currency($vat_price) . '</del>';
  153.         $write .= ' <small style="font-size:11px;color:grey;">price includes VAT</small><br>';
  154.       } else {
  155.         $write .= '<del class="old1">' . foxyshop_currency($no_vat_price) . '</del>';
  156.       }
  157.       if ( $vat_display == 'both' ) {
  158.         $write .= '<del class="foxyshop_oldprice_no_vat old2">' . foxyshop_currency($no_vat_sale_price) . '</del>';
  159.         $write .= ' <small style="font-size:11px;color:grey;">price excluding VAT</small><br>';
  160.       }
  161.     }
  162.     if ( $vat_display == 'on' || $vat_display == 'both' ) {
  163.       $write .= '<span class=" foxyshop_saleprice old3">' . foxyshop_currency($vat_sale_price) . '</span>';
  164.       $write .= ' <small style="font-size:11px;color:grey;">price includes VAT</small>';
  165.     } else {
  166.       $write .= '<span class=" foxyshop_saleprice old3">' . foxyshop_currency($no_vat_sale_price) . '</span>';
  167.     }
  168.     if ( $vat_display == 'both' ) {
  169.       $write .= '<br><span class="foxyshop_currentprice_no_vat foxyshop_saleprice old4">' . foxyshop_currency($no_vat_sale_price) . '</span>';
  170.       $write .= ' <small style="font-size:11px;color:grey;">price excluding VAT</small>';
  171.     }
  172.  
  173.  
  174.   }
  175.   $write .= '</div>';
  176.  
  177.  
  178.  
  179.   if ($echo_output) {
  180.     echo $write;
  181.   } else {
  182.     return $write;
  183.   }
  184. }
RAW Paste Data
Top