WooCommerce_Extra_Fee_Option

The WooCommerce Extra Fee Option WooCommerce Extra Fee Option class.

Defined (1)

The class is defined in the following location(s).

/wc-extra-fee-option.php  
  1. class WooCommerce_Extra_Fee_Option{ 
  2.  
  3. public static $plugin_prefix; 
  4. public static $plugin_url; 
  5. public static $plugin_path; 
  6. public static $plugin_basefile; 
  7.  
  8. var $textdomain; 
  9. var $types; 
  10. var $options_extra_fee_option; 
  11. var $saved_options_extra_fee_option; 
  12.  
  13. /** 
  14. * Gets things started by adding an action to initialize this plugin once 
  15. * WooCommerce is known to be active and initialized 
  16. */ 
  17. public function __construct() { 
  18. load_plugin_textdomain('wc-extra-fee-option', false, dirname(plugin_basename(__FILE__)) . '/languages/'); 
  19.  
  20. WooCommerce_Extra_Fee_Option::$plugin_prefix = 'wc_extra_fee_option_'; 
  21. WooCommerce_Extra_Fee_Option::$plugin_basefile = plugin_basename(__FILE__); 
  22. WooCommerce_Extra_Fee_Option::$plugin_url = plugin_dir_url(WooCommerce_Extra_Fee_Option::$plugin_basefile); 
  23. WooCommerce_Extra_Fee_Option::$plugin_path = trailingslashit(dirname(__FILE__)); 
  24.  
  25. $this->textdomain = 'wc-extra-fee-option'; 
  26.  
  27. $this->types = array('fixed' => 'Fixed Fee', 'percentage' => 'Cart Percentage(%)'); 
  28.  
  29. $this->options_extra_fee_option = array( 
  30. 'extra_fee_option_enabled' => '',  
  31. 'extra_fee_option_label' => 'Extra Fee',  
  32. 'extra_fee_option_type' => 'fixed',  
  33. 'extra_fee_option_cost' => 0,  
  34. 'extra_fee_option_taxable' => false,  
  35. 'extra_fee_option_minorder' => 0,  
  36. ); 
  37.  
  38. $this->saved_options_extra_fee_option = array(); 
  39.  
  40. add_action('woocommerce_init', array(&$this, 'init')); 
  41.  
  42. /** 
  43. * Initialize extension when WooCommerce is active 
  44. */ 
  45. public function init() { 
  46.  
  47. //add menu link for the plugin (backend) 
  48. add_action( 'admin_menu', array( &$this, 'add_menu_extra_fee_option' ) ); 
  49.  
  50. //add admin css3 button stylesheet 
  51. //add_action('admin_init', array( &$this, 'tsang_plugin_admin_init') ); 
  52.  
  53. if(get_option('extra_fee_option_enabled')) 
  54. //add_action( 'woocommerce_before_calculate_totals', array( &$this, 'woo_add_extra_fee') ); 
  55. add_action( 'woocommerce_cart_calculate_fees', array( &$this, 'woo_add_extra_fee') ); 
  56.  
  57. function tsang_plugin_admin_init() { 
  58. /** Register admin stylesheet. */ 
  59. wp_register_style( 'tsangPluginStylesheet', plugins_url('css/admin.css', __FILE__) ); 
  60.  
  61. function tsang_plugin_admin_styles() { 
  62. /** 
  63. * It will be called only on your plugin admin page, enqueue our stylesheet here 
  64. */ 
  65. wp_enqueue_style( 'tsangPluginStylesheet' ); 
  66.  
  67. function remove_currency($price) { 
  68. return (double) preg_replace('/[^0-9.]+/', '', $price); 
  69.  
  70. /** 
  71. * Set the extra fee with min order total limit 
  72. */ 
  73. public function woo_add_extra_fee() { 
  74. global $woocommerce; 
  75.  
  76. $extra_fee_option_label = get_option( 'extra_fee_option_label' ) ? get_option( 'extra_fee_option_label' ) : 'Extra Fee'; 
  77. $extra_fee_option_cost = get_option( 'extra_fee_option_cost' ) ? get_option( 'extra_fee_option_cost' ) : '0'; 
  78. $extra_fee_option_type = get_option( 'extra_fee_option_type' ) ? get_option( 'extra_fee_option_type' ) : 'fixed'; 
  79. $extra_fee_option_taxable = get_option( 'extra_fee_option_taxable' ) ? get_option( 'extra_fee_option_taxable' ) : false; 
  80. $extra_fee_option_minorder = get_option( 'extra_fee_option_minorder' ) ? get_option( 'extra_fee_option_minorder' ) : '0'; 
  81.  
  82. //get cart total 
  83. $total = $this->remove_currency($woocommerce->cart->get_cart_total()); 
  84.  
  85. //check for fee type (fixed fee or cart %) 
  86. if($extra_fee_option_type == 'percentage') { 
  87. $extra_fee_option_cost = ($extra_fee_option_cost / 100) * $total; 
  88. }  
  89.  
  90. //round the cost to 2 decimal points - fixed Paypal problem raised by Robbo870 
  91. $extra_fee_option_cost = round($extra_fee_option_cost, 2); 
  92.  
  93. //if cart total less or equal than $min_order, add extra fee 
  94. if($extra_fee_option_minorder > 0) { 
  95. if($total <= $extra_fee_option_minorder) { 
  96. $woocommerce->cart->add_fee( __($extra_fee_option_label, 'woocommerce'), $extra_fee_option_cost, $extra_fee_option_taxable ); 
  97. } else { 
  98. $woocommerce->cart->add_fee( __($extra_fee_option_label, 'woocommerce'), $extra_fee_option_cost, $extra_fee_option_taxable ); 
  99.  
  100. /** 
  101. * Add a menu link to the woocommerce section menu 
  102. */ 
  103. function add_menu_extra_fee_option() { 
  104. $wc_page = 'woocommerce'; 
  105. $comparable_settings_page = add_submenu_page( $wc_page , __( 'Extra Fee Option', $this->textdomain ), __( 'Extra Fee Option', $this->textdomain ), 'manage_options', 'wc-extra-fee-option', array( 
  106. &$this,  
  107. 'settings_page_extra_fee_option' 
  108. )); 
  109.  
  110. add_action( 'admin_print_styles-' . $comparable_settings_page, array( &$this, 'tsang_plugin_admin_styles') ); 
  111.  
  112. /** 
  113. * Create the settings page content 
  114. */ 
  115. public function settings_page_extra_fee_option() { 
  116.  
  117. // If form was submitted 
  118. if ( isset( $_POST['submitted'] ) ) 
  119. check_admin_referer( $this->textdomain ); 
  120.  
  121. $this->saved_options_extra_fee_option['extra_fee_option_enabled'] = ! isset( $_POST['extra_fee_option_enabled'] ) ? '1' : $_POST['extra_fee_option_enabled']; 
  122. $this->saved_options_extra_fee_option['extra_fee_option_label'] = ! isset( $_POST['extra_fee_option_label'] ) ? 'Extra Fee' : $_POST['extra_fee_option_label']; 
  123. $this->saved_options_extra_fee_option['extra_fee_option_cost'] = ! isset( $_POST['extra_fee_option_cost'] ) ? 0 : $_POST['extra_fee_option_cost']; 
  124. $this->saved_options_extra_fee_option['extra_fee_option_type'] = ! isset( $_POST['extra_fee_option_type'] ) ? 'fixed' : $_POST['extra_fee_option_type']; 
  125. $this->saved_options_extra_fee_option['extra_fee_option_taxable'] = ! isset( $_POST['extra_fee_option_taxable'] ) ? false : $_POST['extra_fee_option_taxable']; 
  126. $this->saved_options_extra_fee_option['extra_fee_option_minorder'] = ! isset( $_POST['extra_fee_option_minorder'] ) ? 0 : $_POST['extra_fee_option_minorder']; 
  127.  
  128. foreach($this->options_extra_fee_option as $field => $value) 
  129. $option_extra_fee_option = get_option( $field ); 
  130.  
  131. if($option_extra_fee_option != $this->saved_options_extra_fee_option[$field]) 
  132. update_option( $field, $this->saved_options_extra_fee_option[$field] ); 
  133.  
  134. // Show message 
  135. echo '<div id="message" class="updated fade"><p>' . __( 'WooCommerce Extra Fee Option options saved.', $this->textdomain ) . '</p></div>'; 
  136.  
  137. $extra_fee_option_enabled = get_option( 'extra_fee_option_enabled' ); 
  138. $extra_fee_option_label = get_option( 'extra_fee_option_label' ) ? get_option( 'extra_fee_option_label' ) : 'Extra Fee'; 
  139. $extra_fee_option_cost = get_option( 'extra_fee_option_cost' ) ? get_option( 'extra_fee_option_cost' ) : '0'; 
  140. $extra_fee_option_type = get_option( 'extra_fee_option_type' ) ? get_option( 'extra_fee_option_type' ) : 'fixed'; 
  141. $extra_fee_option_taxable = get_option( 'extra_fee_option_taxable' ) ? get_option( 'extra_fee_option_taxable' ) : false; 
  142. $extra_fee_option_minorder = get_option( 'extra_fee_option_minorder' ) ? get_option( 'extra_fee_option_minorder' ) : '0'; 
  143.  
  144. $checked_enabled = ''; 
  145. $checked_taxable = ''; 
  146.  
  147. if($extra_fee_option_enabled) 
  148. $checked_enabled = 'checked="checked"'; 
  149.  
  150. if($extra_fee_option_taxable) 
  151. $checked_taxable = 'checked="checked"'; 
  152.  
  153.  
  154. $actionurl = $_SERVER['REQUEST_URI']; 
  155. $nonce = wp_create_nonce( $this->textdomain ); 
  156.  
  157.  
  158. // Configuration Page 
  159.  
  160. ?> 
  161. <div id="icon-options-general" class="icon32"></div> 
  162. <h3><?php _e( 'Extra Fee Option', $this->textdomain); ?></h3> 
  163.  
  164.  
  165. <table width="90%" cellspacing="2"> 
  166. <tr> 
  167. <td width="70%" valign="top"> 
  168. <form action="<?php echo $actionurl; ?>" method="post"> 
  169. <table> 
  170. <tbody> 
  171. <tr> 
  172. <td colspan="2"> 
  173. <table class="widefat auto" cellspacing="2" cellpadding="2" border="0"> 
  174. <tr> 
  175. <td width="25%"><?php _e( 'Enable', $this->textdomain ); ?></td> 
  176. <td> 
  177. <input class="checkbox" name="extra_fee_option_enabled" id="extra_fee_option_enabled" value="0" type="hidden"> 
  178. <input class="checkbox" name="extra_fee_option_enabled" id="extra_fee_option_enabled" value="1" <?php echo $checked_enabled; ?> type="checkbox"> 
  179. </td> 
  180. </tr> 
  181. <tr> 
  182. <td><?php _e( 'Label', $this->textdomain ); ?></td> 
  183. <td> 
  184. <input type="text" id="extra_fee_option_label" name="extra_fee_option_label" value="<?php echo $extra_fee_option_label; ?>" size="30" /> 
  185. </td> 
  186. </tr> 
  187. <tr> 
  188. <td><?php _e( 'Amount', $this->textdomain ); ?></td> 
  189. <td> 
  190. <input type="text" id="extra_fee_option_cost" name="extra_fee_option_cost" value="<?php echo $extra_fee_option_cost; ?>" size="10" /> 
  191. </td> 
  192. </tr> 
  193. <tr> 
  194. <td width="25%"><?php _e( 'Type', $this->textdomain ); ?></td> 
  195. <td> 
  196. <select name="extra_fee_option_type"> 
  197. <option value="fixed" <?php if($extra_fee_option_type == 'fixed') { echo 'selected="selected"'; } ?>><?php _e( 'Fixed Fee', $this->textdomain ); ?></option> 
  198. <option value="percentage" <?php if($extra_fee_option_type == 'percentage') { echo 'selected="selected"'; } ?>><?php _e( 'Cart Percentage(%)', $this->textdomain ); ?></option> 
  199. </select> 
  200. </td> 
  201. </tr> 
  202. <tr> 
  203. <td width="25%"><?php _e( 'Taxable', $this->textdomain ); ?></td> 
  204. <td> 
  205. <input class="checkbox" name="extra_fee_option_taxable" id="extra_fee_option_taxable" value="0" type="hidden"> 
  206. <input class="checkbox" name="extra_fee_option_taxable" id="extra_fee_option_taxable" value="1" <?php echo $checked_taxable; ?> type="checkbox"> 
  207. </td> 
  208. </tr> 
  209. <tr> 
  210. <td><?php _e( 'Minumum Order<br><span style="color:#999;">(Optional, apply extra fee when cart total is less or equal than this amount)</span>', $this->textdomain ); ?></td> 
  211. <td> 
  212. <?php echo get_woocommerce_currency_symbol(); ?> <input type="text" id="extra_fee_option_minorder" name="extra_fee_option_minorder" value="<?php echo $extra_fee_option_minorder; ?>" size="10" /> 
  213. </td> 
  214. </tr> 
  215. </table> 
  216. </td> 
  217. </tr> 
  218. <tr> 
  219. <td colspan=2"> 
  220. <input class="button-primary" type="submit" name="Save" value="<?php _e('Save Options', $this->textdomain); ?>" id="submitbutton" /> 
  221. <input type="hidden" name="submitted" value="1" />  
  222. <input type="hidden" id="_wpnonce" name="_wpnonce" value="<?php echo $nonce; ?>" /> 
  223. </td> 
  224. </tr> 
  225. </tbody> 
  226. </table> 
  227. </form> 
  228.  
  229. </td> 
  230.  
  231. <td width="30%" style="background:#ececec;padding:10px 5px;" valign="top"> 
  232. <p><b>WooCommerce Extra Fee Option</b> is a FREE woocommerce plugin developed by <a href="http://shop.terrytsang.com" target="_blank" title="Terry Tsang - a PHP Developer and Wordpress Consultant">Terry Tsang</a>. This plugin aims to add extra fee minimum order for WooCommerce.</p> 
  233.  
  234. <?php 
  235. $get_pro_image = WooCommerce_Extra_Fee_Option::$plugin_url . '/images/pro-version.png'; 
  236. ?> 
  237. <p align="center"><a href="http://terrytsang.com/shop/shop/woocommerce-extra-fee-option-pro/" target="_blank" title="WooCommerce Extra Fee Options PRO"><img src="<?php echo $get_pro_image; ?>" border="0" /></a></p> 
  238.  
  239. <h3>Spreading the Word</h3> 
  240.  
  241. <ul style="list-style:dash">If you find this plugin helpful, you can:  
  242. <li>- Write and review about it in your blog</li> 
  243. <li>- Rate it on <a href="http://wordpress.org/extend/plugins/woocommerce-extra-fee-option/" target="_blank">wordpress plugin page</a></li> 
  244. <li>- Share on your social media<br /> 
  245. <a href="http://www.facebook.com/sharer.php?u=http://terrytsang.com/shop/shop/woocommerce-extra-fee-option/&t=WooCommerce Extra Fee Option" title="Share this WooCommerce Extra Fee Option on Facebook" target="_blank"><img src="http://terrytsang.com/shop/images/social_facebook.png" alt="Share this WooCommerce Extra Fee Option plugin on Facebook"></a>  
  246. <a href="https://twitter.com/intent/tweet?url=http%3A%2F%2Fterrytsang.com%2Fshop%2Fshop%2Fwoocommerce-extra-fee-option%2F&text=WooCommerce Extra Fee Option - &via=terrytsang811" target="_blank"><img src="http://terrytsang.com/shop/images/social_twitter.png" alt="Tweet about WooCommerce Extra Fee Option plugin"></a> 
  247. <a href="http://linkedin.com/shareArticle?mini=true&url=http://terrytsang.com/shop/shop/woocommerce-extra-fee-option/&title=WooCommerce Extra Fee Option plugin" title="Share this WooCommerce Extra Fee Option plugin on LinkedIn" target="_blank"><img src="http://terrytsang.com/shop/images/social_linkedin.png" alt="Share this WooCommerce Extra Fee Option plugin on LinkedIn"></a> 
  248. </li> 
  249. <li>- Or make a donation</li> 
  250. </ul> 
  251.  
  252. <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LJWSJDBBLNK7W" target="_blank"><img src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" alt="" /></a> 
  253.  
  254. <h3>Thank you for your support!</h3> 
  255. </td> 
  256.  
  257. </tr> 
  258. </table> 
  259.  
  260.  
  261. <br /> 
  262.  
  263. <?php 
  264.  
  265. /** 
  266. * Get the setting options 
  267. */ 
  268. function get_options() { 
  269.  
  270. foreach($this->options_extra_fee_option as $field => $value) 
  271. $array_options[$field] = get_option( $field ); 
  272.  
  273. return $array_options; 
  274.  
  275. /** 
  276. * Load javascript for the page 
  277. */ 
  278. /**public function script_extra_fee_option() 
  279. wp_enqueue_script( 'jquery-ui-datepicker' ); 
  280. wp_enqueue_script( 'custom-plugin-script', plugins_url('/js/script.js', __FILE__)); 
  281. }*/ 
  282.  
  283. /** 
  284. * Load stylesheet for the page 
  285. */ 
  286. /**public function stylesheet_extra_fee_option() { 
  287. wp_register_style( 'custom-plugin-stylesheet', plugins_url('/css/style.css', __FILE__) ); 
  288. wp_enqueue_style( 'custom-plugin-stylesheet' ); 
  289. }*/ 
  290.  
  291. }//end class