Changeset 2926190
- Timestamp:
- 06/14/2023 09:37:01 PM (21 months ago)
- Location:
- role-based-bulk-quantity-pricing/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
role-based-bulk-quantity-pricing/trunk/Readme.txt
r2926096 r2926190 1 1 === Role Based Bulk Quantity Pricing === 2 Contributors: kevinamorim 2 Contributors: kevinamorim, freemius 3 3 Tags: pricing, csv, roles, woocommerce, bulk 4 4 Requires at least: 5.5 -
role-based-bulk-quantity-pricing/trunk/assets/js/scripts.js
r2926092 r2926190 53 53 let taxesMessage = ''; 54 54 55 /* <fs_premium_only> */ 56 if ( display_tax_info ) { 57 taxesMessage = taxes_included == true ? 58 rbbqp_localized_strings.including_vat_message : 59 rbbqp_localized_strings.excluding_vat_message; 60 } 61 /* </fs_premium_only> */ 55 62 56 63 57 if ( productType === 'variable' ) { -
role-based-bulk-quantity-pricing/trunk/inc/admin/class-rbbqp-settings.php
r2926092 r2926190 3 3 namespace Role_Based_Bulk_Quantity_Pricing\Inc\Admin; 4 4 5 defined( 'ABSPATH' ) || exit; // Exit if accessed directly. 6 7 use Role_Based_Bulk_Quantity_Pricing\Inc; 8 use Role_Based_Bulk_Quantity_Pricing\Inc\Data\Repositories; 9 10 class Rbbqp_Settings { 11 12 private $data_accessor; 13 private $options_manager; 14 15 private $page_slug; 16 17 private $pricing_lines; 18 19 public function __construct() { 20 5 defined( 'ABSPATH' ) || exit; 6 // Exit if accessed directly. 7 use Role_Based_Bulk_Quantity_Pricing\Inc ; 8 use Role_Based_Bulk_Quantity_Pricing\Inc\Data\Repositories ; 9 class Rbbqp_Settings 10 { 11 private $data_accessor ; 12 private $options_manager ; 13 private $page_slug ; 14 private $pricing_lines ; 15 public function __construct() 16 { 21 17 $this->page_slug = 'role-based-bulk-quantity-pricing-settings'; 22 23 18 $this->data_accessor = new Inc\Rbbqp_Data_Accessor(); 24 19 $this->options_manager = Inc\Rbbqp_Options_Manager::get_instance(); 25 26 20 add_action( 'admin_menu', array( $this, 'create_menu_page' ) ); 27 21 add_action( 'admin_init', array( $this, 'render_fields' ) ); 28 22 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); 29 23 } 30 31 public function enqueue_admin_scripts() { 32 wp_enqueue_script( 'rbbqp_admin_scripts', plugin_dir_url( __FILE__ ) . '../../assets/js/admin-scripts.js', array( 'jquery' ), '1.0.5' ); 33 wp_enqueue_style( 'bootstrap', plugin_dir_url( __FILE__ ) . '../../assets/libs/bootstrap.min.css' ); 34 wp_localize_script( 'rbbqp_admin_scripts', 'rbbqp_localized_strings', array( 35 'ajax_url' => admin_url( 'admin-ajax.php' ), 36 'processing_message' => __( 'Processing... Please wait!', 'role-based-bulk-quantity-pricing' ), 37 'upload_success_message' => __( 'A total of: %s lines were uploaded with success!', 'role-based-bulk-quantity-pricing' ) 38 ) 39 ); 24 25 public function enqueue_admin_scripts() 26 { 27 wp_enqueue_script( 28 'rbbqp_admin_scripts', 29 plugin_dir_url( __FILE__ ) . '../../assets/js/admin-scripts.js', 30 array( 'jquery' ), 31 '1.0.5' 32 ); 33 wp_enqueue_style( 'bootstrap', plugin_dir_url( __FILE__ ) . '../../assets/libs/bootstrap.min.css' ); 34 wp_localize_script( 'rbbqp_admin_scripts', 'rbbqp_localized_strings', array( 35 'ajax_url' => admin_url( 'admin-ajax.php' ), 36 'processing_message' => __( 'Processing... Please wait!', 'role-based-bulk-quantity-pricing' ), 37 'upload_success_message' => __( 'A total of: %s lines were uploaded with success!', 'role-based-bulk-quantity-pricing' ), 38 ) ); 40 39 wp_set_script_translations( 'rbbqp_admin_scripts', 'role-based-bulk-quantity-pricing' ); 41 wp_enqueue_style( 'rbbqp_admin_styles', plugin_dir_url( __FILE__ ) . '../../assets/css/admin-styles.css', array( 'bootstrap' ), '1.0.5' ); 42 } 43 44 public function create_menu_page() { 40 wp_enqueue_style( 41 'rbbqp_admin_styles', 42 plugin_dir_url( __FILE__ ) . '../../assets/css/admin-styles.css', 43 array( 'bootstrap' ), 44 '1.0.5' 45 ); 46 } 47 48 public function create_menu_page() 49 { 45 50 add_menu_page( 46 __( 'Role Based Bulk Quantity Pricing', 'role-based-bulk-quantity-pricing' ),47 __( 'Role Based Bulk Quantity Pricing', 'role-based-bulk-quantity-pricing' ), 51 __( 'Role Based Bulk Quantity Pricing', 'role-based-bulk-quantity-pricing' ), 52 __( 'Role Based Bulk Quantity Pricing', 'role-based-bulk-quantity-pricing' ), 48 53 'read', 49 54 $this->page_slug, 50 55 array( $this, 'display_settings_page' ) 51 56 ); 52 53 57 add_submenu_page( 54 58 $this->page_slug, 55 __( 'Dashboard', 'role-based-bulk-quantity-pricing' ), 56 __( 'Dashboard', 'role-based-bulk-quantity-pricing' ), 59 __( 'Dashboard', 'role-based-bulk-quantity-pricing' ), 60 __( 'Dashboard', 'role-based-bulk-quantity-pricing' ), 57 61 'read', 58 62 $this->page_slug 59 63 ); 60 61 64 add_submenu_page( 62 65 $this->page_slug, 63 __( 'Configurations', 'role-based-bulk-quantity-pricing' ), 64 __( 'Configurations', 'role-based-bulk-quantity-pricing' ), 66 __( 'Configurations', 'role-based-bulk-quantity-pricing' ), 67 __( 'Configurations', 'role-based-bulk-quantity-pricing' ), 65 68 'read', 66 69 'role-based-bulk-quantity-pricing-configurations', … … 68 71 ); 69 72 } 70 71 public function render_fields() { 73 74 public function render_fields() 75 { 72 76 add_settings_section( 73 77 'configurations_section', 74 78 __( 'Configurations', 'role-based-bulk-quantity-pricing' ), 75 79 array( $this, 'options_section' ), 76 $this->page_slug 77 ); 78 } 79 80 public function configurations_submenu() {81 80 $this->page_slug 81 ); 82 } 83 84 public function configurations_submenu() 85 { 82 86 $configurations_saved = false; 83 if ( isset( $_POST ) &&84 87 88 if ( isset( $_POST ) && isset( $_POST['submit'] ) ) { 85 89 $this->submit_configurations( $_POST ); 86 90 $configurations_saved = true; 87 91 } 88 92 89 93 ?> 90 94 91 95 <div class="wrap"> 92 96 <h2 class="nav-tab-wrapper" id="settings"> 93 <a href="<?php echo esc_url( get_site_url() . '/wp-admin/admin.php?page=role-based-bulk-quantity-pricing-configurations' );?>" class="nav-tab nav-tab-active home">Settings</a> 97 <a href="<?php 98 echo esc_url( get_site_url() . '/wp-admin/admin.php?page=role-based-bulk-quantity-pricing-configurations' ) ; 99 ?>" class="nav-tab nav-tab-active home">Settings</a> 94 100 </h2> 95 101 96 102 <form method="post" name="rbbqpSettingsForm"> 97 103 98 <?php if( $configurations_saved ): ?> 104 <?php 105 106 if ( $configurations_saved ) { 107 ?> 99 108 <div id="savedSuccessAlert" class="alert alert-success mt-5" role="alert"> 100 <?php _e('Configurations saved!', 'role-based-bulk-quantity-pricing' ); ?> 109 <?php 110 _e( 'Configurations saved!', 'role-based-bulk-quantity-pricing' ); 111 ?> 101 112 </div> 102 <?php endif; ?> 103 104 105 <?php do_settings_sections( $this->page_slug ); ?> 113 <?php 114 } 115 116 ?> 117 118 119 <?php 120 do_settings_sections( $this->page_slug ); 121 ?> 106 122 <hr> 107 123 <button class="btn btn-success rbbqp_custom_submit_button" type="submit" class="button" name="submit" value="Submit"> 108 <img width="17" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '../../assets/img/save.svg' ) ?>" /> <?php _e( 'Save', 'role-based-bulk-quantity-pricing' ) ?> 124 <img width="17" src="<?php 125 echo esc_url( plugin_dir_url( __FILE__ ) . '../../assets/img/save.svg' ) ; 126 ?>" /> <?php 127 _e( 'Save', 'role-based-bulk-quantity-pricing' ); 128 ?> 109 129 </button> 110 130 </form> 111 131 112 132 <div class="rbbqp-brand-logo-container"> 113 <img class="rbbqp-brand-logo" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '../../assets/img/logo.png' ) ?>" /> 114 </div> 115 116 </div> 117 118 <?php 119 } 120 121 public function options_section() { 122 133 <img class="rbbqp-brand-logo" src="<?php 134 echo esc_url( plugin_dir_url( __FILE__ ) . '../../assets/img/logo.png' ) ; 135 ?>" /> 136 </div> 137 138 </div> 139 140 <?php 141 } 142 143 public function options_section() 144 { 123 145 $use_roles = $this->options_manager->get_use_roles_option(); 124 146 $use_total_cart_qty = $this->options_manager->get_use_total_cart_qty_option(); 125 147 $allow_for_guest = $this->options_manager->get_allow_for_guest_option(); 126 148 $debug_mode = $this->options_manager->get_debug_mode_option(); 127 128 if ( rbbqp_fs()->is__premium_only() ) {129 $hide_taxes_on_product_page_for_wp_option_name = $this->options_manager->get_hide_taxes_on_product_page_for_option__premium_only();130 $display_tax_information = $this->options_manager->get_display_tax_information_option__premium_only();131 }132 133 149 $display_product_total = $this->options_manager->get_display_product_total_option(); 134 135 150 ?> 136 151 <div class="row mt-5"> 137 152 <div class="col-2"> 138 <label class="rbbqp_custom_label" for="useRoles"><?php _e( 'Use Roles', 'role-based-bulk-quantity-pricing' ) ?>:</label> 153 <label class="rbbqp_custom_label" for="useRoles"><?php 154 _e( 'Use Roles', 'role-based-bulk-quantity-pricing' ); 155 ?>:</label> 139 156 </div> 140 157 <div class="col-10"> 141 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="useRoles" value="Yes" <?php echo isset( $use_roles ) && $use_roles == "1" ? "checked" : ""; ?> /> 158 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="useRoles" value="Yes" <?php 159 echo ( isset( $use_roles ) && $use_roles == "1" ? "checked" : "" ) ; 160 ?> /> 142 161 </div> 143 162 </div> … … 145 164 <div class="row mt-2"> 146 165 <div class="col-2"> 147 <label class="rbbqp_custom_label" for="useTotalCartQty"><?php _e( 'Use Total Cart Quantity', 'role-based-bulk-quantity-pricing' ) ?>:</label> 166 <label class="rbbqp_custom_label" for="useTotalCartQty"><?php 167 _e( 'Use Total Cart Quantity', 'role-based-bulk-quantity-pricing' ); 168 ?>:</label> 148 169 </div> 149 170 <div class="col-10"> 150 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="useTotalCartQty" value="Yes" <?php echo esc_attr( isset( $use_total_cart_qty ) && $use_total_cart_qty == "1" ? "checked" : "" ); ?> /> 171 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="useTotalCartQty" value="Yes" <?php 172 echo esc_attr( ( isset( $use_total_cart_qty ) && $use_total_cart_qty == "1" ? "checked" : "" ) ) ; 173 ?> /> 151 174 </div> 152 175 </div> … … 154 177 <div class="row mt-2"> 155 178 <div class="col-2"> 156 <label class="rbbqp_custom_label" for="allowForGuest"><?php _e( 'Allow For Guest', 'role-based-bulk-quantity-pricing' ) ?>:</label> 179 <label class="rbbqp_custom_label" for="allowForGuest"><?php 180 _e( 'Allow For Guest', 'role-based-bulk-quantity-pricing' ); 181 ?>:</label> 157 182 </div> 158 183 <div class="col-10"> 159 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="allowForGuest" value="Yes" <?php echo esc_attr( isset( $allow_for_guest ) && $allow_for_guest == "1" ? "checked" : "" ); ?> /> 184 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="allowForGuest" value="Yes" <?php 185 echo esc_attr( ( isset( $allow_for_guest ) && $allow_for_guest == "1" ? "checked" : "" ) ) ; 186 ?> /> 160 187 </div> 161 188 </div> … … 163 190 <div class="row mt-2"> 164 191 <div class="col-2"> 165 <label class="rbbqp_custom_label" for="displayProductTotal"><?php _e( 'Display Product Total', 'role-based-bulk-quantity-pricing' ) ?>:</label> 192 <label class="rbbqp_custom_label" for="displayProductTotal"><?php 193 _e( 'Display Product Total', 'role-based-bulk-quantity-pricing' ); 194 ?>:</label> 166 195 </div> 167 196 <div class="col-10"> 168 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="displayProductTotal" value="Yes" <?php echo esc_attr( isset( $display_product_total ) && $display_product_total == "1" ? "checked" : "" ); ?> /> 197 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="displayProductTotal" value="Yes" <?php 198 echo esc_attr( ( isset( $display_product_total ) && $display_product_total == "1" ? "checked" : "" ) ) ; 199 ?> /> 169 200 </div> 170 201 </div> … … 172 203 <hr /> 173 204 174 <?php 175 176 if ( rbbqp_fs()->is__premium_only() ) { 177 178 ?> 179 <h5><?php _e( 'Taxes', 'role-based-bulk-quantity-pricing' ); ?></h5> 180 181 <div class="row mt-2"> 182 <div class="col-2"> 183 <label class="rbbqp_custom_label" for="displayTaxInformation"><?php _e( 'Display Tax Information', 'role-based-bulk-quantity-pricing' ) ?>:</label> 184 </div> 185 <div class="col-10"> 186 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="displayTaxInformation" value="Yes" <?php echo esc_attr( isset( $display_tax_information ) && $display_tax_information == "1" ? "checked" : "" ); ?> /> 187 <small class="rbbqp_label_info"><?php _e( 'A message saying whether the price includes or not taxes will be displayed next to the product price.', 'role-based-bulk-quantity-pricing' ); ?></small> 188 </div> 189 </div> 190 191 <div class="row mt-2"> 192 <div class="col-2"> 193 <label class="rbbqp_custom_label" for="excludedRolesFromTaxesDisplay"><?php _e( 'Hide taxes on product page for roles', 'role-based-bulk-quantity-pricing' ) ?>:</label> 194 </div> 195 <div class="col-10"> 196 <input class="form-control" type="text" name="excludedRolesFromTaxesDisplay" value="<?php echo esc_attr( $hide_taxes_on_product_page_for_wp_option_name ); ?>" /> 197 <small class="rbbqp_label_info"><?php _e( 'Comma-separated list, without spaces, all lower case (equal to the CSV file).', 'role-based-bulk-quantity-pricing' ); ?></small> 198 <small class="rbbqp_label_info"><?php _e( 'Taxes will not be displayed on the product page for the selected roles.', 'role-based-bulk-quantity-pricing' ); ?></small> 199 </div> 200 </div> 201 <hr /> 202 203 <?php } ?> 204 205 <h5><?php _e( 'Advanced', 'role-based-bulk-quantity-pricing' ); ?></h5> 205 <?php 206 ?> 207 208 <h5><?php 209 _e( 'Advanced', 'role-based-bulk-quantity-pricing' ); 210 ?></h5> 206 211 207 212 <div class="row mt-2"> 208 213 <div class="col-2"> 209 <label class="rbbqp_custom_label" for="debugMode"><?php _e( 'Debug Mode', 'role-based-bulk-quantity-pricing' ) ?>:</label> 214 <label class="rbbqp_custom_label" for="debugMode"><?php 215 _e( 'Debug Mode', 'role-based-bulk-quantity-pricing' ); 216 ?>:</label> 210 217 </div> 211 218 <div class="col-10"> 212 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="debugMode" value="Yes" <?php echo esc_attr( isset( $debug_mode ) && $debug_mode == "1" ? "checked" : "" ); ?> /> 213 </div> 214 </div> 215 <?php 216 } 217 218 public function submit_configurations( $data ) { 219 219 <input class="form-control rbbqp_custom_checkbox_input" type="checkbox" name="debugMode" value="Yes" <?php 220 echo esc_attr( ( isset( $debug_mode ) && $debug_mode == "1" ? "checked" : "" ) ) ; 221 ?> /> 222 </div> 223 </div> 224 <?php 225 } 226 227 public function submit_configurations( $data ) 228 { 229 220 230 if ( isset( $data["useRoles"] ) && $data["useRoles"] == "Yes" ) { 221 $this->options_manager->set_use_roles_option( true ); 231 $this->options_manager->set_use_roles_option( true ); 222 232 } else { 223 233 $this->options_manager->set_use_roles_option( false ); 224 } 225 234 } 235 236 226 237 if ( isset( $data["useTotalCartQty"] ) && $data["useTotalCartQty"] == "Yes" ) { 227 238 $this->options_manager->set_use_total_cart_qty_option( true ); … … 230 241 } 231 242 232 if ( isset( $data["allowForGuest"] ) && $data["allowForGuest"] == "Yes" ) { 243 244 if ( isset( $data["allowForGuest"] ) && $data["allowForGuest"] == "Yes" ) { 233 245 $this->options_manager->set_allow_for_guest_option( true ); 234 246 } else { 235 247 $this->options_manager->set_allow_for_guest_option( false ); 236 248 } 237 238 if ( isset( $data["displayProductTotal"] ) && $data["displayProductTotal"] == "Yes" ) { 249 250 251 if ( isset( $data["displayProductTotal"] ) && $data["displayProductTotal"] == "Yes" ) { 239 252 $this->options_manager->set_display_product_total_option( true ); 240 253 } else { 241 254 $this->options_manager->set_display_product_total_option( false ); 242 255 } 243 244 /** 245 * Premium only! 246 */ 247 if ( rbbqp_fs()->is__premium_only() ) { 248 249 if ( isset( $data["displayTaxInformation"] ) && $data["displayTaxInformation"] == "Yes" ) { 250 $this->options_manager->set_display_tax_information_option__premium_only( true ); 251 } else { 252 $this->options_manager->set_display_tax_information_option__premium_only( false ); 253 } 254 255 if ( isset( $data["excludedRolesFromTaxesDisplay"] ) ) { 256 $data_excludedRolesFromTaxesDisplay = sanitize_text_field( $data["excludedRolesFromTaxesDisplay"] ); 257 258 $fixed_str = str_replace( ' ', '', $data_excludedRolesFromTaxesDisplay ); 259 $fixed_str = strtolower( $fixed_str ); 260 $this->options_manager->set_hide_taxes_on_product_page_for_option__premium_only( $fixed_str ); 261 } 262 } 263 264 if ( isset( $data["debugMode"] ) && $data["debugMode"] == "Yes" ) { 256 257 258 if ( isset( $data["debugMode"] ) && $data["debugMode"] == "Yes" ) { 265 259 $this->options_manager->set_debug_mode_option( true ); 266 260 } else { 267 261 $this->options_manager->set_debug_mode_option( false ); 268 262 } 269 270 } 271 272 public function display_settings_page() { 263 264 } 265 266 public function display_settings_page() 267 { 273 268 $page = 1; 274 269 $count = Repositories\Rbbqp_Pricing_Repository::get_count(); 275 $totalPages = 270 $totalPages = ceil( $count / 10 ); 276 271 ?> 277 272 278 273 <div class="row"> 279 274 <div class="col-12"> 280 <h2><?php _e( 'Dashboard', 'role-based-bulk-quantity-pricing' ); ?></h2> 275 <h2><?php 276 _e( 'Dashboard', 'role-based-bulk-quantity-pricing' ); 277 ?></h2> 281 278 </div> 282 279 </div> … … 284 281 <div class="row"> 285 282 <div class="col-md-4"> 286 <button type="button" id="exportCsvBtn" class="btn btn-primary"><?php _e('Export CSV', 'role-based-bulk-quantity-pricing' ) ?></button><br> 283 <button type="button" id="exportCsvBtn" class="btn btn-primary"><?php 284 _e( 'Export CSV', 'role-based-bulk-quantity-pricing' ); 285 ?></button><br> 287 286 </div> 288 287 <div class="col-md-4"> 289 <button type="button" id="exportProductsListBtn" class="btn btn-primary"><?php _e('Export Products List', 'role-based-bulk-quantity-pricing' ) ?></button><br> 290 <span id="exportProductsListDownloadMsg" style="display:none;"><?php _e( 'Processing... Please wait!', 'role-based-bulk-quantity-pricing' ); ?></span> 288 <button type="button" id="exportProductsListBtn" class="btn btn-primary"><?php 289 _e( 'Export Products List', 'role-based-bulk-quantity-pricing' ); 290 ?></button><br> 291 <span id="exportProductsListDownloadMsg" style="display:none;"><?php 292 _e( 'Processing... Please wait!', 'role-based-bulk-quantity-pricing' ); 293 ?></span> 291 294 </div> 292 295 <div class="col-md-4"> 293 <button type="button" id="exportRolesBtn" class="btn btn-primary"><?php _e('Export Roles List', 'role-based-bulk-quantity-pricing' ) ?></button><br> 294 <span id="exportRolesDownloadMsg" style="display:none;"><?php _e( 'Processing... Please wait!', 'role-based-bulk-quantity-pricing' ); ?></span> 296 <button type="button" id="exportRolesBtn" class="btn btn-primary"><?php 297 _e( 'Export Roles List', 'role-based-bulk-quantity-pricing' ); 298 ?></button><br> 299 <span id="exportRolesDownloadMsg" style="display:none;"><?php 300 _e( 'Processing... Please wait!', 'role-based-bulk-quantity-pricing' ); 301 ?></span> 295 302 </div> 296 303 </div> … … 302 309 <div class="row mt-5"> 303 310 <div class="col-md-12"> 304 <table id="pricingLinesTable" class="table" data-current-page="<?php echo esc_attr( $page ); ?>" data-total-pages="<?php echo esc_attr( $totalPages ); ?>"> 311 <table id="pricingLinesTable" class="table" data-current-page="<?php 312 echo esc_attr( $page ) ; 313 ?>" data-total-pages="<?php 314 echo esc_attr( $totalPages ) ; 315 ?>"> 305 316 306 317 <thead> 307 318 <tr> 308 <th scope="col"><?php _e( 'ID', 'role-based-bulk-quantity-pricing' ); ?></th> 309 <th scope="col"><?php _e( 'Role', 'role-based-bulk-quantity-pricing' ); ?></th> 310 <th scope="col"><?php _e( 'Base Unit Price', 'role-based-bulk-quantity-pricing' ); ?></th> 311 <th scope="col"><?php _e( 'Threshold Unit Price', 'role-based-bulk-quantity-pricing' ); ?></th> 312 <th scope="col"><?php _e( 'Threshold Quantity', 'role-based-bulk-quantity-pricing' ); ?></th> 319 <th scope="col"><?php 320 _e( 'ID', 'role-based-bulk-quantity-pricing' ); 321 ?></th> 322 <th scope="col"><?php 323 _e( 'Role', 'role-based-bulk-quantity-pricing' ); 324 ?></th> 325 <th scope="col"><?php 326 _e( 'Base Unit Price', 'role-based-bulk-quantity-pricing' ); 327 ?></th> 328 <th scope="col"><?php 329 _e( 'Threshold Unit Price', 'role-based-bulk-quantity-pricing' ); 330 ?></th> 331 <th scope="col"><?php 332 _e( 'Threshold Quantity', 'role-based-bulk-quantity-pricing' ); 333 ?></th> 313 334 </tr> 314 335 </thead> … … 323 344 <li class="page-item"> 324 345 <a class="page-link" 325 href="#" onclick="rbbqp_previousPage(); return false;"><?php _e( 'Previous', 'role-based-bulk-quantity-pricing' ); ?></a> 346 href="#" onclick="rbbqp_previousPage(); return false;"><?php 347 _e( 'Previous', 'role-based-bulk-quantity-pricing' ); 348 ?></a> 326 349 </li> 327 <?php for($i = 1; $i <= $totalPages; $i++ ): ?> 328 <li class="page-item" data-id="<?php echo $i; ?>"> 329 <a class="page-link" href="#" onclick="rbbqp_fetchPage(<?php echo esc_js( $i ); ?>); return false;"> <?php echo esc_html( $i ); ?> </a> 350 <?php 351 for ( $i = 1 ; $i <= $totalPages ; $i++ ) { 352 ?> 353 <li class="page-item" data-id="<?php 354 echo $i ; 355 ?>"> 356 <a class="page-link" href="#" onclick="rbbqp_fetchPage(<?php 357 echo esc_js( $i ) ; 358 ?>); return false;"> <?php 359 echo esc_html( $i ) ; 360 ?> </a> 330 361 </li> 331 <?php endfor; ?> 362 <?php 363 } 364 ?> 332 365 <li class="page-item"> 333 366 <a class="page-link" 334 href="#" onclick="rbbqp_nextPage(); return false;"><?php _e( 'Next', 'role-based-bulk-quantity-pricing' ); ?></a> 367 href="#" onclick="rbbqp_nextPage(); return false;"><?php 368 _e( 'Next', 'role-based-bulk-quantity-pricing' ); 369 ?></a> 335 370 </li> 336 371 </ul> … … 345 380 <input type='file' name='file' id="csvFileToUploadInput"> 346 381 <button class="btn btn-success rbbqp_custom_submit_button" type="submit" class="button" name="btn_submit" disabled> 347 <img width="17" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '../../assets/img/save.svg' ); ?>" /> <?php _e( 'Import CSV', 'role-based-bulk-quantity-pricing' ) ?> 382 <img width="17" src="<?php 383 echo esc_url( plugin_dir_url( __FILE__ ) . '../../assets/img/save.svg' ) ; 384 ?>" /> <?php 385 _e( 'Import CSV', 'role-based-bulk-quantity-pricing' ); 386 ?> 348 387 </button> 349 388 <div class="row mt-5"> 350 389 <div class="col-md-12"> 351 390 <span id="uploadingCsvMsg" style="display: none;"> 352 <?php _e('The uploaded file is processing... Please, do not leave or refresh this page.', 'role-based-bulk-quantity-pricing' ); ?> 391 <?php 392 _e( 'The uploaded file is processing... Please, do not leave or refresh this page.', 'role-based-bulk-quantity-pricing' ); 393 ?> 353 394 </span> 354 395 </div> … … 358 399 359 400 <div class="rbbqp-brand-logo-container"> 360 <img class="rbbqp-brand-logo" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '../../assets/img/logo.png' ); ?>" /> 361 </div> 362 363 <?php 364 } 401 <img class="rbbqp-brand-logo" src="<?php 402 echo esc_url( plugin_dir_url( __FILE__ ) . '../../assets/img/logo.png' ) ; 403 ?>" /> 404 </div> 405 406 <?php 407 } 408 365 409 } -
role-based-bulk-quantity-pricing/trunk/inc/class-rbbqp-options-manager.php
r2926092 r2926190 3 3 namespace Role_Based_Bulk_Quantity_Pricing\Inc; 4 4 5 defined( 'ABSPATH' ) || exit; // Exit if accessed directly.6 7 class Rbbqp_Options_Manager {8 9 private static $instance;10 11 public static function get_instance(){5 defined( 'ABSPATH' ) || exit; 6 // Exit if accessed directly. 7 class Rbbqp_Options_Manager 8 { 9 private static $instance ; 10 public static function get_instance() 11 { 12 12 if ( null === self::$instance ) { 13 13 self::$instance = new self(); 14 14 } 15 16 15 return self::$instance; 17 16 } 18 19 private $prefix;20 21 private $options;22 23 private $use_roles_wp_option_name;24 private $use_total_cart_qty_wp_option_name;25 private $allow_for_guest_wp_option_name;26 private $debug_mode_wp_option_name;27 28 private $hide_taxes_on_product_page_for_wp_option_name;29 private $display_tax_information_wp_option_name;30 17 31 public function __construct() { 32 18 private $prefix ; 19 private $options ; 20 private $use_roles_wp_option_name ; 21 private $use_total_cart_qty_wp_option_name ; 22 private $allow_for_guest_wp_option_name ; 23 private $debug_mode_wp_option_name ; 24 private $hide_taxes_on_product_page_for_wp_option_name ; 25 private $display_tax_information_wp_option_name ; 26 public function __construct() 27 { 33 28 $this->prefix = 'rbbqp_'; 34 35 29 $this->options = get_option( $this->prefix . 'options' ); 36 if ( !$this->options ) 30 if ( !$this->options ) { 37 31 $this->options = array(); 38 32 } 39 33 $this->use_roles_wp_option_name = 'use_roles'; 40 34 $this->use_total_cart_qty_wp_option_name = 'use_total_cart_qty'; 41 35 $this->allow_for_guest_wp_option_name = 'allow_for_guest'; 42 36 $this->debug_mode_wp_option_name = 'debug_mode'; 43 44 37 /** Premium only configurations. */ 45 38 $this->hide_taxes_on_product_page_for_wp_option_name = 'hide_taxes_on_product_page_for'; 46 39 $this->display_tax_information_wp_option_name = 'display_tax_information'; 47 48 40 $this->display_product_total = "display_product_total"; 49 41 } 50 51 private function get_value_or_default( $key, $default = false ) { 42 43 private function get_value_or_default( $key, $default = false ) 44 { 52 45 if ( array_key_exists( $key, $this->options ) ) { 53 46 return $this->options[$key]; … … 55 48 return $default; 56 49 } 57 58 private function set_value( $key, $value ) { 50 51 private function set_value( $key, $value ) 52 { 59 53 $this->options[$key] = $value; 60 update_option( $this->prefix . 'options', $this->options ); 54 update_option( $this->prefix . 'options', $this->options ); 61 55 } 62 63 public function get_use_roles_option() { 56 57 public function get_use_roles_option() 58 { 64 59 return $this->get_value_or_default( $this->use_roles_wp_option_name ); 65 60 } 66 67 public function set_use_roles_option( $new_value ) { 61 62 public function set_use_roles_option( $new_value ) 63 { 68 64 $this->set_value( $this->use_roles_wp_option_name, $new_value ); 69 65 } 70 71 public function get_use_total_cart_qty_option() { 66 67 public function get_use_total_cart_qty_option() 68 { 72 69 return $this->get_value_or_default( $this->use_total_cart_qty_wp_option_name ); 73 70 } 74 75 public function set_use_total_cart_qty_option( $new_value ) { 71 72 public function set_use_total_cart_qty_option( $new_value ) 73 { 76 74 $this->set_value( $this->use_total_cart_qty_wp_option_name, $new_value ); 77 75 } 78 79 public function get_allow_for_guest_option() { 76 77 public function get_allow_for_guest_option() 78 { 80 79 return $this->get_value_or_default( $this->allow_for_guest_wp_option_name ); 81 80 } 82 83 public function set_allow_for_guest_option( $new_value ) { 81 82 public function set_allow_for_guest_option( $new_value ) 83 { 84 84 $this->set_value( $this->allow_for_guest_wp_option_name, $new_value ); 85 85 } 86 87 public function get_debug_mode_option() { 86 87 public function get_debug_mode_option() 88 { 88 89 return $this->get_value_or_default( $this->debug_mode_wp_option_name ); 89 90 } 90 91 public function set_debug_mode_option( $new_value ) { 91 92 public function set_debug_mode_option( $new_value ) 93 { 92 94 $this->set_value( $this->debug_mode_wp_option_name, $new_value ); 93 95 } 94 95 public function get_display_product_total_option() { 96 97 public function get_display_product_total_option() 98 { 96 99 return $this->get_value_or_default( $this->display_product_total ); 97 100 } 98 99 public function set_display_product_total_option( $new_value ) { 101 102 public function set_display_product_total_option( $new_value ) 103 { 100 104 $this->set_value( $this->display_product_total, $new_value ); 101 105 } 102 106 103 /**104 * Premium only.105 */106 public function get_hide_taxes_on_product_page_for_option__premium_only() {107 return $this->get_value_or_default( $this->hide_taxes_on_product_page_for_wp_option_name );108 }109 110 public function set_hide_taxes_on_product_page_for_option__premium_only( $new_value ) {111 $this->set_value( $this->hide_taxes_on_product_page_for_wp_option_name, $new_value );112 }113 114 public function get_display_tax_information_option__premium_only() {115 return $this->get_value_or_default( $this->display_tax_information_wp_option_name );116 }117 118 public function set_display_tax_information_option__premium_only( $new_value ) {119 $this->set_value( $this->display_tax_information_wp_option_name, $new_value );120 }121 107 } -
role-based-bulk-quantity-pricing/trunk/inc/class-rbbqp-product-helper.php
r2926092 r2926190 3 3 namespace Role_Based_Bulk_Quantity_Pricing\Inc; 4 4 5 defined( 'ABSPATH' ) || exit; // Exit if accessed directly. 6 7 use Role_Based_Bulk_Quantity_Pricing\Inc; 8 use Role_Based_Bulk_Quantity_Pricing\Inc\Helpers; 9 use Role_Based_Bulk_Quantity_Pricing\Inc\Helpers\Models; 10 11 class Rbbqp_Product_Helper { 12 13 private $options_manager; 14 private $rbbqp_cart_helper; 15 private $rbbqp_tax_helper; 16 private $user_helpers; 17 private $price_helpers; 18 19 private $display_taxes; 20 21 private $roles; 22 5 defined( 'ABSPATH' ) || exit; 6 // Exit if accessed directly. 7 use Role_Based_Bulk_Quantity_Pricing\Inc ; 8 use Role_Based_Bulk_Quantity_Pricing\Inc\Helpers ; 9 use Role_Based_Bulk_Quantity_Pricing\Inc\Helpers\Models ; 10 class Rbbqp_Product_Helper 11 { 12 private $options_manager ; 13 private $rbbqp_cart_helper ; 14 private $rbbqp_tax_helper ; 15 private $user_helpers ; 16 private $price_helpers ; 17 private $display_taxes ; 18 private $roles ; 23 19 /** 24 20 * Options 25 21 */ 26 private $debug_mode; 27 private $handle_taxes; 28 private $display_tax_information; 29 private $use_total_cart_qty; 30 private $display_product_total; 31 32 public function __construct() { 33 22 private $debug_mode ; 23 private $handle_taxes ; 24 private $display_tax_information ; 25 private $use_total_cart_qty ; 26 private $display_product_total ; 27 public function __construct() 28 { 34 29 add_action( 'woocommerce_single_product_summary', array( $this, 'total_product_price' ), 31 ); 35 add_action( 'woocommerce_get_price_html', array( $this, 'total_product_price_html' ), 99, 2 ); 36 37 add_filter('woocommerce_product_get_price', array( $this, 'product_get_price' ), 9999, 2 ); 38 add_filter('woocommerce_get_price_excluding_tax', array( $this, 'product_get_price_excl_taxes' ), 9999, 3 ); 39 add_filter('woocommerce_product_get_regular_price', array( $this, 'product_get_price' ), 9999, 2 ); 40 add_filter('safe_style_css', array( $this, 'add_display_as_safe_style_css' ), 9999, 1 ); 41 30 add_action( 31 'woocommerce_get_price_html', 32 array( $this, 'total_product_price_html' ), 33 99, 34 2 35 ); 36 add_filter( 37 'woocommerce_product_get_price', 38 array( $this, 'product_get_price' ), 39 9999, 40 2 41 ); 42 add_filter( 43 'woocommerce_get_price_excluding_tax', 44 array( $this, 'product_get_price_excl_taxes' ), 45 9999, 46 3 47 ); 48 add_filter( 49 'woocommerce_product_get_regular_price', 50 array( $this, 'product_get_price' ), 51 9999, 52 2 53 ); 54 add_filter( 55 'safe_style_css', 56 array( $this, 'add_display_as_safe_style_css' ), 57 9999, 58 1 59 ); 42 60 $this->rbbqp_cart_helper = new Rbbqp_Cart_Helper(); 43 61 $this->rbbqp_tax_helper = new Rbbqp_Tax_Helper(); … … 45 63 $this->user_helpers = new Helpers\Rbbqp_User_Helpers(); 46 64 $this->price_helpers = new Inc\Rbbqp_Price_Helper(); 47 48 65 $this->roles = $this->user_helpers->get_user_roles(); 49 50 66 $this->debug_mode = $this->options_manager->get_debug_mode_option(); 51 52 if ( rbbqp_fs()->is__premium_only() ) { 53 $this->display_tax_information = $this->options_manager->get_display_tax_information_option__premium_only() == "1" ? true : false; 54 } else { 55 $this->display_tax_information = false; 56 } 57 67 $this->display_tax_information = false; 58 68 $this->use_total_cart_qty = $this->options_manager->get_use_total_cart_qty_option(); 59 69 $this->display_product_total = $this->options_manager->get_display_product_total_option(); 60 61 70 $this->display_taxes = $this->rbbqp_tax_helper->should_display_taxes(); 62 71 } 63 64 public function add_display_as_safe_style_css( $styles ) { 72 73 public function add_display_as_safe_style_css( $styles ) 74 { 65 75 $styles[] = 'display'; 66 76 return $styles; 67 77 } 68 69 public function product_get_price( $price, $product ) {70 71 if ( is_admin() || defined( 'REST_REQUEST') )78 79 public function product_get_price( $price, $product ) 80 { 81 if ( is_admin() || defined( 'REST_REQUEST' ) ) { 72 82 return; 73 83 } 74 84 $cart_quantity = $this->rbbqp_cart_helper->get_item_quantity( $product->get_id(), 0 ); 75 76 return $this->price_helpers->get_item_price( $product, $price, $cart_quantity, false, true ); 77 } 78 79 public function product_get_price_excl_taxes( $price, $qty, $product ) { 80 return $this->price_helpers->get_item_price( $product, $price, $qty, false, true ); 81 } 82 85 return $this->price_helpers->get_item_price( 86 $product, 87 $price, 88 $cart_quantity, 89 false, 90 true 91 ); 92 } 93 94 public function product_get_price_excl_taxes( $price, $qty, $product ) 95 { 96 return $this->price_helpers->get_item_price( 97 $product, 98 $price, 99 $qty, 100 false, 101 true 102 ); 103 } 104 83 105 /** 84 106 * Prices displayed on product page. 85 107 */ 86 public function total_product_price() {87 88 if ( is_admin() || defined( 'REST_REQUEST') )108 public function total_product_price() 109 { 110 if ( is_admin() || defined( 'REST_REQUEST' ) ) { 89 111 return; 90 91 global $woocommerce, $product;112 } 113 global $woocommerce, $product ; 92 114 $product_type = $product->get_type(); 93 94 115 $json_ob = array(); 95 116 96 117 if ( $product->is_type( 'variable' ) ) { 97 98 118 $variations = $product->get_available_variations(); 99 100 119 foreach ( $variations as $key => $value ) { 101 120 $pricing_lines = $this->price_helpers->get_all_pricings_for_item( $value['variation_id'], $product ); 102 $json_ob = $this->add_pricing_to_json_obj( $json_ob, $pricing_lines, $value['variation_id'], $value ); 121 $json_ob = $this->add_pricing_to_json_obj( 122 $json_ob, 123 $pricing_lines, 124 $value['variation_id'], 125 $value 126 ); 103 127 } 104 105 128 ?> 106 129 <script> 107 rbbqp_updateCurrentPrice( '<?php echo esc_js( $product_type ); ?>', '<?php echo esc_js( $this->display_tax_information ); ?>', '<?php echo esc_js( $this->display_taxes ); ?>', -1 ); 130 rbbqp_updateCurrentPrice( '<?php 131 echo esc_js( $product_type ) ; 132 ?>', '<?php 133 echo esc_js( $this->display_tax_information ) ; 134 ?>', '<?php 135 echo esc_js( $this->display_taxes ) ; 136 ?>', -1 ); 108 137 </script> 109 <?php 138 <?php 110 139 } else { 111 112 140 $pricing_lines = $this->price_helpers->get_all_pricings_for_item( $product->get_id(), $product ); 113 $json_ob = $this->add_pricing_to_json_obj( $json_ob, $pricing_lines, $product->get_id(), $product ); 114 141 $json_ob = $this->add_pricing_to_json_obj( 142 $json_ob, 143 $pricing_lines, 144 $product->get_id(), 145 $product 146 ); 115 147 ?> 116 148 <script> 117 rbbqp_updateCurrentPrice( '<?php echo esc_js( $product_type ); ?>', '<?php echo esc_js( $this->display_tax_information ); ?>', '<?php echo esc_js( $this->display_taxes ); ?>', '<?php echo esc_js( $product->get_id() ); ?>' ); 149 rbbqp_updateCurrentPrice( '<?php 150 echo esc_js( $product_type ) ; 151 ?>', '<?php 152 echo esc_js( $this->display_tax_information ) ; 153 ?>', '<?php 154 echo esc_js( $this->display_taxes ) ; 155 ?>', '<?php 156 echo esc_js( $product->get_id() ) ; 157 ?>' ); 118 158 </script> 119 <?php 120 121 } 122 159 <?php 160 } 161 123 162 $customPricingTable_html = sprintf( '<div style="display:none;" id="customPricingTable" data-json="' . htmlspecialchars( json_encode( $json_ob ), ENT_QUOTES, 'UTF-8' ) . '"></div>' ); 124 echo wp_kses( 125 $customPricingTable_html, 126 array( 127 'div' => array( 128 'id' => array(), 129 'data-json' => array(), 130 'style' => array(), 131 ) ) ); 132 163 echo wp_kses( $customPricingTable_html, array( 164 'div' => array( 165 'id' => array(), 166 'data-json' => array(), 167 'style' => array(), 168 ), 169 ) ) ; 170 133 171 if ( $this->display_product_total ) { 134 echo wp_kses( 135 sprintf( '<div id="product_total_price" style="margin:5px auto;">%s %s</div>',__( 'Product Total:', 'role-based-bulk-quantity-pricing' ),'<span class="price"></span>' ), 136 array( 137 'div' => array( 138 'id' => array(), 139 'style' => array(), 140 ), 141 'span' => array( 142 'class' => array() 143 ) 144 ) ); 145 echo wp_kses( 146 sprintf( '<div id="product_unit_price" style="margin:5px auto;">%s %s</div>',__( 'Unit Price:', 'role-based-bulk-quantity-pricing' ),'<span class="price"></span>' ), 147 array( 148 'div' => array( 149 'id' => array(), 150 'style' => array(), 151 ), 152 'span' => array( 153 'class' => array() 154 ) 155 ) ); 172 echo wp_kses( sprintf( '<div id="product_total_price" style="margin:5px auto;">%s %s</div>', __( 'Product Total:', 'role-based-bulk-quantity-pricing' ), '<span class="price"></span>' ), array( 173 'div' => array( 174 'id' => array(), 175 'style' => array(), 176 ), 177 'span' => array( 178 'class' => array(), 179 ), 180 ) ) ; 181 echo wp_kses( sprintf( '<div id="product_unit_price" style="margin:5px auto;">%s %s</div>', __( 'Unit Price:', 'role-based-bulk-quantity-pricing' ), '<span class="price"></span>' ), array( 182 'div' => array( 183 'id' => array(), 184 'style' => array(), 185 ), 186 'span' => array( 187 'class' => array(), 188 ), 189 ) ) ; 156 190 } 157 191 158 192 $this->maybe_print_debug_data(); 159 193 } 160 194 161 195 /** 162 196 * If debug mode is set to TRUE then some useful information will be displayed on the product page. 163 197 */ 164 private function maybe_print_debug_data() {165 166 if ( $this->debug_mode != '1' ) 198 private function maybe_print_debug_data() 199 { 200 if ( $this->debug_mode != '1' ) { 167 201 return; 168 169 echo wp_kses( 170 sprintf('<div id="user_assigned_roles_debug" class="rbbqp_debug-message">%s %s %s</div>', __('Assigned Roles','role-based-bulk-quantity-pricing'), ':', print_r( $this->roles, true ) ), 171 array( 172 'div' => array( 173 'id' => array(), 174 'class' => array(), 175 'data-json' => array(), 176 'style' => array(), 177 ) ) 178 ); 179 } 180 202 } 203 echo wp_kses( sprintf( 204 '<div id="user_assigned_roles_debug" class="rbbqp_debug-message">%s %s %s</div>', 205 __( 'Assigned Roles', 'role-based-bulk-quantity-pricing' ), 206 ':', 207 print_r( $this->roles, true ) 208 ), array( 209 'div' => array( 210 'id' => array(), 211 'class' => array(), 212 'data-json' => array(), 213 'style' => array(), 214 ), 215 ) ) ; 216 } 217 181 218 /** 182 219 * JUST FOR THE DISPLAY FOR VARIABLE PRODUCTS 183 220 * TODO: REFACTOR 184 221 */ 185 186 public function total_product_price_html( $price, $product_obj ) { 187 188 if ( is_admin() || defined('REST_REQUEST') ) 222 public function total_product_price_html( $price, $product_obj ) 223 { 224 if ( is_admin() || defined( 'REST_REQUEST' ) ) { 189 225 return $price; 190 191 global $product; 192 226 } 227 global $product ; 193 228 $product_type = $product->get_type(); 194 195 if ( 'variable' !== $product->get_type() || 196 'product_variation' === $product_obj->post_type ) { 197 198 if ( rbbqp_fs()->is__premium_only() ) { 199 200 $calculated_price = $this->price_helpers->get_item_price( $product, $product->get_price(), 1, false, !$this->display_taxes ); 201 202 if ( $this->display_tax_information ) { 203 $price = wc_price( $calculated_price ) . ( $this->display_taxes ? ' (with VAT)' : ' (without VAT)' ); 204 } else { 205 $price = wc_price( $calculated_price ); 206 } 207 208 return $price; 209 210 } else { 211 return $price; 212 } 213 } 214 229 if ( 'variable' !== $product->get_type() || 'product_variation' === $product_obj->post_type ) { 230 return $price; 231 } 215 232 $variations = $product->get_available_variations(); 216 217 233 $min_price = 99999; 218 234 $max_price = 0; 219 220 235 foreach ( $variations as $key => $value ) { 221 236 $pricing_lines = $this->price_helpers->get_all_pricings_for_item( $value['variation_id'], $product ); 222 223 if ( is_array( $pricing_lines) && count ( $pricing_lines ) > 0 ) { 224 225 for ( $x = 0; $x < count( $pricing_lines ); $x++ ) { 226 237 238 if ( is_array( $pricing_lines ) && count( $pricing_lines ) > 0 ) { 239 for ( $x = 0 ; $x < count( $pricing_lines ) ; $x++ ) { 240 227 241 if ( $pricing_lines[$x]->base_unit_price > $max_price ) { 228 242 $max_price = $pricing_lines[$x]->base_unit_price; 229 } else if ( $pricing_lines[$x]->base_unit_price < $min_price ) { 230 $min_price = $pricing_lines[$x]->base_unit_price; 243 } else { 244 if ( $pricing_lines[$x]->base_unit_price < $min_price ) { 245 $min_price = $pricing_lines[$x]->base_unit_price; 246 } 231 247 } 232 248 249 233 250 if ( $pricing_lines[$x]->threshold_unit_price > $max_price ) { 234 251 $max_price = $pricing_lines[$x]->threshold_unit_price; 235 } else if ( $pricing_lines[$x]->threshold_unit_price < $min_price ) { 236 $min_price = $pricing_lines[$x]->threshold_unit_price; 252 } else { 253 if ( $pricing_lines[$x]->threshold_unit_price < $min_price ) { 254 $min_price = $pricing_lines[$x]->threshold_unit_price; 255 } 237 256 } 257 238 258 } 239 259 } else { 240 if ( $value['display_price'] < $min_price ) 241 $min_price = $value['display_price']; 260 if ( $value['display_price'] < $min_price ) { 261 $min_price = $value['display_price']; 262 } 242 263 } 243 }244 264 265 } 245 266 $prices = array( $min_price, $max_price ); 246 247 if ( rbbqp_fs()->is__premium_only() ) { 248 249 if ( $this->display_tax_information ) { 250 $price = $prices[0] !== $prices[1] ? 251 sprintf( __( 'From: %s %s', 'role-based-bulk-quantity-pricing' ), wc_price( $prices[0] ), ( $this->display_taxes ? ' (with VAT)' : ' (without VAT)' ) ) : 252 wc_price( $prices[0] ) . ( $this->display_taxes ? ' (with VAT)' : ' (without VAT)' ); 253 return $price; 254 } 255 256 } 257 258 $price = $prices[0] !== $prices[1] ? 259 sprintf( __( 'From: %s', 'role-based-bulk-quantity-pricing' ), wc_price( $prices[0] ) ) : 260 wc_price( $prices[0] ); 261 267 $price = ( $prices[0] !== $prices[1] ? sprintf( __( 'From: %s', 'role-based-bulk-quantity-pricing' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ) ); 262 268 return $price; 263 269 } 264 265 private function add_pricing_to_json_obj( $json_ob, $pricing_lines, $item_id, $item ) { 266 270 271 private function add_pricing_to_json_obj( 272 $json_ob, 273 $pricing_lines, 274 $item_id, 275 $item 276 ) 277 { 278 267 279 if ( is_array( $item ) ) { 268 280 $price = $item['display_price']; … … 270 282 $price = $item->get_price(); 271 283 } 272 284 273 285 $initial_quantity = $this->rbbqp_cart_helper->get_item_quantity( $item_id, 0 ); 274 275 if ( is_null( $pricing_lines ) || empty( $pricing_lines) ) {276 $json_ob[$item_id] = array( array( 277 'threshold_min_qty' => 0,278 'base_unit_price' => $price,286 287 if ( is_null( $pricing_lines ) || empty($pricing_lines) ) { 288 $json_ob[$item_id] = array( array( 289 'threshold_min_qty' => 0, 290 'base_unit_price' => $price, 279 291 'threshold_unit_price' => $price, 280 'initial_quantity' => $initial_quantity ) ); 292 'initial_quantity' => $initial_quantity, 293 ) ); 281 294 } else { 282 283 295 foreach ( $pricing_lines as $key => $pricing_line ) { 284 296 $pricing_line->initial_quantity = $initial_quantity; 285 297 } 298 $json_ob[$item_id] = $pricing_lines; 299 } 300 301 return $json_ob; 302 } 286 303 287 $json_ob[$item_id] = $pricing_lines;288 }289 290 return $json_ob;291 }292 304 } -
role-based-bulk-quantity-pricing/trunk/inc/class-rbbqp-tax-helper.php
r2926092 r2926190 3 3 namespace Role_Based_Bulk_Quantity_Pricing\Inc; 4 4 5 defined( 'ABSPATH' ) || exit; // Exit if accessed directly. 6 7 use Role_Based_Bulk_Quantity_Pricing\Inc; 8 use Role_Based_Bulk_Quantity_Pricing\Inc\Helpers; 9 use Role_Based_Bulk_Quantity_Pricing\Inc\Helpers\Models; 10 5 defined( 'ABSPATH' ) || exit; 6 // Exit if accessed directly. 7 use Role_Based_Bulk_Quantity_Pricing\Inc ; 8 use Role_Based_Bulk_Quantity_Pricing\Inc\Helpers ; 9 use Role_Based_Bulk_Quantity_Pricing\Inc\Helpers\Models ; 11 10 /** 12 11 * Helper class for taxes operations. 13 12 * 14 13 */ 15 class Rbbqp_Tax_Helper { 16 17 private $wc_tax; 18 private $options_manager; 19 private $user_helpers; 20 14 class Rbbqp_Tax_Helper 15 { 16 private $wc_tax ; 17 private $options_manager ; 18 private $user_helpers ; 21 19 /** 22 20 * Options 23 21 */ 24 private $debug_mode; 25 private $tax_display_shop; 26 private $hide_taxes_on_product_page_for; 27 28 public function __construct() { 29 22 private $debug_mode ; 23 private $tax_display_shop ; 24 private $hide_taxes_on_product_page_for ; 25 public function __construct() 26 { 30 27 $this->wc_tax = new \WC_Tax(); 31 28 $this->options_manager = Inc\Rbbqp_Options_Manager::get_instance(); 32 29 $this->user_helpers = new Helpers\Rbbqp_User_Helpers(); 33 34 30 $this->debug_mode = $this->options_manager->get_debug_mode_option(); 35 36 if ( rbbqp_fs()->is__premium_only() ) { 37 $this->hide_taxes_on_product_page_for = $this->options_manager->get_hide_taxes_on_product_page_for_option__premium_only(); 38 } else { 39 $this->hide_taxes_on_product_page_for = ''; 40 } 41 31 $this->hide_taxes_on_product_page_for = ''; 42 32 $this->tax_display_shop = get_option( 'woocommerce_tax_display_shop' ); 43 33 } 44 34 45 35 /** 46 36 * Gets the tax rate for a given tax class and customer location (optional). … … 51 41 * @return array Object containing: error message (if any), success, rate, multiplier, customer location. 52 42 */ 53 public function get_tax_rate( $tax_class, $ignore_customer_location = false ) : Models\Rbbqp_Item_Tax_Model { 54 55 56 43 public function get_tax_rate( $tax_class, $ignore_customer_location = false ) : Models\Rbbqp_Item_Tax_Model 44 { 45 57 46 if ( !$ignore_customer_location ) { 58 59 47 $location = $this->get_customer_location(); 60 $taxes = $this->wc_tax->find_rates( array_merge( 61 $location, 62 array( 'tax_class' => $tax_class ) 63 ) ); 64 48 $taxes = $this->wc_tax->find_rates( array_merge( $location, array( 49 'tax_class' => $tax_class, 50 ) ) ); 65 51 } else { 66 67 52 $taxes = $this->wc_tax->get_rates_for_tax_class( '' ); 68 53 $location = __( 'Ignored', 'role-based-bulk-quantity-pricing' ); 69 54 } 70 71 55 72 if ( is_array( $taxes ) && count ( $taxes ) > 0 ) {73 56 57 if ( is_array( $taxes ) && count( $taxes ) > 0 ) { 74 58 // Take the first item. 75 59 $rates = array_shift( $taxes ); 76 60 $item_rate = round( $rates->tax_rate ); 77 $rate_multiplier = 1 + ( $item_rate / 100 ); 78 61 $rate_multiplier = 1 + $item_rate / 100; 79 62 $this->maybe_print_debug_data( $item_rate, $location, '-' ); 80 81 return new Models\Rbbqp_Item_Tax_Model( 82 $item_rate, 83 $rate_multiplier, 84 $ignore_customer_location ? $location : $location['country'] ); 85 63 return new Models\Rbbqp_Item_Tax_Model( $item_rate, $rate_multiplier, ( $ignore_customer_location ? $location : $location['country'] ) ); 86 64 } 87 65 88 66 $this->maybe_print_debug_data( 0, $location, __( 'No tax rate found for product.', 'role-based-bulk-quantity-pricing' ) ); 89 90 return new Models\Rbbqp_Item_Tax_Model( 91 0, 92 1, 93 $ignore_customer_location ? $location : $location['country'], 67 return new Models\Rbbqp_Item_Tax_Model( 68 0, 69 1, 70 ( $ignore_customer_location ? $location : $location['country'] ), 94 71 __( 'No tax rate found for product.', 'role-based-bulk-quantity-pricing' ), 95 72 false 96 );97 }98 99 private function get_customer_location() {100 return array(101 'country' => WC()->customer->get_shipping_country() ? WC()->customer->get_shipping_country() : WC()->customer->get_billing_country(),102 'state' => WC()->customer->get_shipping_state() ? WC()->customer->get_shipping_state() : WC()->customer->get_billing_state(),103 'city' => WC()->customer->get_shipping_city() ? WC()->customer->get_shipping_city() : WC()->customer->get_billing_city(),104 'postcode' => WC()->customer->get_shipping_postcode() ? WC()->customer->get_shipping_postcode() : WC()->customer->get_billing_postcode(),105 73 ); 106 74 } 107 75 76 private function get_customer_location() 77 { 78 return array( 79 'country' => ( WC()->customer->get_shipping_country() ? WC()->customer->get_shipping_country() : WC()->customer->get_billing_country() ), 80 'state' => ( WC()->customer->get_shipping_state() ? WC()->customer->get_shipping_state() : WC()->customer->get_billing_state() ), 81 'city' => ( WC()->customer->get_shipping_city() ? WC()->customer->get_shipping_city() : WC()->customer->get_billing_city() ), 82 'postcode' => ( WC()->customer->get_shipping_postcode() ? WC()->customer->get_shipping_postcode() : WC()->customer->get_billing_postcode() ), 83 ); 84 } 85 108 86 /** 109 87 * Checks if taxes should be displayed according to user role and … … 112 90 * @return Boolean 113 91 */ 114 public function should_display_taxes() { 115 116 if ( rbbqp_fs()->is__premium_only() ) { 117 $roles = $this->user_helpers->get_user_roles(); 118 119 $excluded_roles = explode( ',', $this->hide_taxes_on_product_page_for ); 120 121 $current_role_is_excluded = false; 122 for ( $x = 0; $x < count ( $roles ); $x++ ) { 123 if ( in_array( $roles[$x], $excluded_roles ) ) { 124 $current_role_is_excluded = true; 125 break; 126 } 127 } 128 129 return !$current_role_is_excluded; 130 } 131 92 public function should_display_taxes() 93 { 132 94 /* Always display for free version. */ 133 95 return true; 134 96 } 135 136 public function maybe_add_tax_to_pricing_line( $pricing_line, $rate_multiplier ) {137 97 98 public function maybe_add_tax_to_pricing_line( $pricing_line, $rate_multiplier ) 99 { 138 100 if ( wc_prices_include_tax() ) { 139 101 // Prices already include taxes. 140 102 141 103 if ( $this->tax_display_shop == 'excl' ) { 142 104 // Remove taxes … … 144 106 $pricing_line->threshold_unit_price /= $rate_multiplier; 145 107 } 108 146 109 } 147 110 … … 150 113 $pricing_line->threshold_unit_price *= $rate_multiplier; 151 114 } 152 115 153 116 return $pricing_line; 154 155 117 } 156 157 public function apply_taxes_rules( $price, $rate_multiplier, $force_ignore_taxes = false ) { 158 118 119 public function apply_taxes_rules( $price, $rate_multiplier, $force_ignore_taxes = false ) 120 { 121 159 122 if ( wc_prices_include_tax() ) { 160 123 // Prices already include taxes. 161 162 124 if ( $this->tax_display_shop == 'excl' || $force_ignore_taxes ) { 163 125 // Remove taxes 164 return $price /= $rate_multiplier;126 return $price /= $rate_multiplier; 165 127 } 166 167 128 } else { 168 169 129 if ( $this->tax_display_shop == 'incl' && !$force_ignore_taxes ) { 170 130 return $price *= $rate_multiplier; 171 131 } 172 173 132 } 174 133 175 134 return $price; 176 135 } 177 178 136 137 /** 179 138 * If debug mode is set to TRUE then some useful information will be displayed on the product page. 180 139 */ 181 private function maybe_print_debug_data( $item_rate, $tax_location, $taxes_error ) {182 183 if ( $this->debug_mode != '1' ) 140 private function maybe_print_debug_data( $item_rate, $tax_location, $taxes_error ) 141 { 142 if ( $this->debug_mode != '1' ) { 184 143 return; 185 186 echo wp_kses( 187 sprintf('<div id="tax_rate_debug" class="rbbqp_debug-message">%s %s %s %s</div>', __('Tax Rate','role-based-bulk-quantity-pricing'), ':', $item_rate, '%'), 188 array( 189 'div' => array( 190 'id' => array(), 191 'class' => array() 192 ) 193 ) 194 ); 195 echo wp_kses( 196 sprintf('<div id="handle_tax_rate_location" class="rbbqp_debug-message">%s %s %s</div>', __('Country','role-based-bulk-quantity-pricing'), ':', $tax_location), 197 array( 198 'div' => array( 199 'id' => array(), 200 'class' => array() 201 ) 202 ) 203 ); 204 205 echo wp_kses( 206 sprintf('<div id="handle_tax_rate_error" class="rbbqp_debug-message">%s %s %s</div>', __('Tax error','role-based-bulk-quantity-pricing'), ':', ''), 207 array( 208 'div' => array( 209 'id' => array(), 210 'class' => array() 211 ) 212 ) 213 ); 144 } 145 echo wp_kses( sprintf( 146 '<div id="tax_rate_debug" class="rbbqp_debug-message">%s %s %s %s</div>', 147 __( 'Tax Rate', 'role-based-bulk-quantity-pricing' ), 148 ':', 149 $item_rate, 150 '%' 151 ), array( 152 'div' => array( 153 'id' => array(), 154 'class' => array(), 155 ), 156 ) ) ; 157 echo wp_kses( sprintf( 158 '<div id="handle_tax_rate_location" class="rbbqp_debug-message">%s %s %s</div>', 159 __( 'Country', 'role-based-bulk-quantity-pricing' ), 160 ':', 161 $tax_location 162 ), array( 163 'div' => array( 164 'id' => array(), 165 'class' => array(), 166 ), 167 ) ) ; 168 echo wp_kses( sprintf( 169 '<div id="handle_tax_rate_error" class="rbbqp_debug-message">%s %s %s</div>', 170 __( 'Tax error', 'role-based-bulk-quantity-pricing' ), 171 ':', 172 '' 173 ), array( 174 'div' => array( 175 'id' => array(), 176 'class' => array(), 177 ), 178 ) ) ; 214 179 } 215 180 -
role-based-bulk-quantity-pricing/trunk/role-based-bulk-quantity-pricing.php
r2926092 r2926190 1 1 <?php 2 2 3 /* 3 4 Plugin Name: Role Based Bulk Quantity Pricing … … 9 10 Domain Path: /languages 10 11 */ 11 12 12 // If this file is called directly, abort. 13 13 if ( !defined( 'WPINC' ) ) { 14 14 die; 15 15 } 16 17 16 /** 18 17 * Freemius 19 18 */ 20 if ( ! function_exists( 'rbbqp_fs' ) ) { 19 20 if ( !function_exists( 'rbbqp_fs' ) ) { 21 21 // Create a helper function for easy SDK access. 22 function rbbqp_fs() { 23 global $rbbqp_fs; 24 25 if ( ! isset( $rbbqp_fs ) ) { 22 function rbbqp_fs() 23 { 24 global $rbbqp_fs ; 25 26 if ( !isset( $rbbqp_fs ) ) { 26 27 // Include Freemius SDK. 27 require_once dirname(__FILE__) . '/freemius/start.php'; 28 28 require_once dirname( __FILE__ ) . '/freemius/start.php'; 29 29 $rbbqp_fs = fs_dynamic_init( array( 30 'id' => '12373', 31 'slug' => 'role-based-bulk-quantity-pricing', 32 'type' => 'plugin', 33 'public_key' => 'pk_e70ad977c9c6dfbb71a49a8daeb95', 34 'navigation' => 'tabs', 35 'is_premium' => true, 36 'is_premium_only' => false, 37 'has_addons' => false, 38 'has_paid_plans' => true, 39 'menu' => array( 40 'slug' => 'role-based-bulk-quantity-pricing-configurations', 41 'contact' => true, 42 'support' => false, 43 'parent' => array( 44 'slug' => 'role-based-bulk-quantity-pricing-settings', 45 ), 46 ), 47 // Set the SDK to work in a sandbox mode (for development & testing). 48 // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT. 49 'secret_key' => 'sk_Y&c$b)e7kHGqD0uT0zfd3+d[[midI', 30 'id' => '12373', 31 'slug' => 'role-based-bulk-quantity-pricing', 32 'type' => 'plugin', 33 'public_key' => 'pk_e70ad977c9c6dfbb71a49a8daeb95', 34 'navigation' => 'tabs', 35 'is_premium' => false, 36 'is_premium_only' => false, 37 'has_addons' => false, 38 'has_paid_plans' => true, 39 'menu' => array( 40 'slug' => 'role-based-bulk-quantity-pricing-configurations', 41 'contact' => true, 42 'support' => false, 43 'parent' => array( 44 'slug' => 'role-based-bulk-quantity-pricing-settings', 45 ), 46 ), 47 'is_live' => true, 50 48 ) ); 51 49 } 52 50 53 51 return $rbbqp_fs; 54 52 } 55 53 56 54 // Init Freemius. 57 55 rbbqp_fs(); … … 60 58 } 61 59 62 use Role_Based_Bulk_Quantity_Pricing\Inc\Admin; 63 use Role_Based_Bulk_Quantity_Pricing\Inc\Data; 64 use Role_Based_Bulk_Quantity_Pricing\Inc; 65 66 require_once( trailingslashit( dirname( __FILE__ ) ) . 'inc/autoloader.php' ); 67 60 use Role_Based_Bulk_Quantity_Pricing\Inc\Admin ; 61 use Role_Based_Bulk_Quantity_Pricing\Inc\Data ; 62 use Role_Based_Bulk_Quantity_Pricing\Inc ; 63 require_once trailingslashit( dirname( __FILE__ ) ) . 'inc/autoloader.php'; 68 64 if ( !function_exists( 'rbbqp_log_entry' ) ) { 69 function rbbqp_log_entry( $entry, $mode = 'a', $file = 'rbbqp_logs' ) {70 65 function rbbqp_log_entry( $entry, $mode = 'a', $file = 'rbbqp_logs' ) 66 { 71 67 $upload_dir = wp_upload_dir(); 72 68 $upload_dir = $upload_dir['basedir']; 73 74 69 if ( is_array( $entry ) ) { 75 70 $entry = json_encode( $entry ); 76 71 } 77 78 72 $file = $upload_dir . '/' . $file . '.log'; 79 73 $file = fopen( $file, $mode ); … … 82 76 return $bytes; 83 77 } 78 79 } 80 function rbbqpload_plugin_textdomain() 81 { 82 load_plugin_textdomain( 'role-based-bulk-quantity-pricing', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); 84 83 } 85 84 86 function rbbqpload_plugin_textdomain() {87 load_plugin_textdomain( 'role-based-bulk-quantity-pricing', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );88 }89 85 add_action( 'plugins_loaded', 'rbbqpload_plugin_textdomain' ); 90 91 function rbbqp_enqueue_script(){92 86 function rbbqp_enqueue_script() 87 { 88 93 89 if ( !is_admin() ) { 94 95 90 wp_enqueue_script( 'rbbqp-front-script', plugin_dir_url( __FILE__ ) . 'assets/js/scripts.js', array( 'jquery' ) ); 96 97 91 $translation_array = array( 98 92 "currency_symbol" => get_woocommerce_currency_symbol(), 99 93 ); 100 101 if ( rbbqp_fs()->is__premium_only() ) { 102 103 $premium_translation_array = array( 104 "including_vat_message" => "(includes VAT)", 105 "excluding_vat_message" => "(without VAT)" 106 ); 107 108 $translation_array = array_merge( $translation_array, $premium_translation_array ); 109 } 110 111 wp_localize_script( 'rbbqp-front-script', 'rbbqp_localized_strings', $translation_array ); 112 113 wp_enqueue_style( 'rbbqp_admin_styles', plugin_dir_url( __FILE__ ) . 'assets/css/styles.css', array(), '1.0.0' ); 94 wp_localize_script( 'rbbqp-front-script', 'rbbqp_localized_strings', $translation_array ); 95 wp_enqueue_style( 96 'rbbqp_admin_styles', 97 plugin_dir_url( __FILE__ ) . 'assets/css/styles.css', 98 array(), 99 '1.0.0' 100 ); 114 101 } 115 102 116 103 } 104 117 105 add_action( 'wp_enqueue_scripts', 'rbbqp_enqueue_script' ); 118 119 106 /** 120 107 * Activate the plugin. 121 108 */ 122 function rbbqp_activate() { 109 function rbbqp_activate() 110 { 123 111 $db_initializer = new Data\Rbbqp_Db_Initializer(); 124 112 $db_initializer->addPricingTable(); 125 113 } 114 126 115 register_activation_hook( __FILE__, 'rbbqp_activate' ); 127 128 116 add_action( 'init', 'wp_pctc_admin_init' ); 129 function wp_pctc_admin_init() { 130 117 function wp_pctc_admin_init() 118 { 119 131 120 if ( is_admin() ) { 132 121 new Admin\Rbbqp_Admin_Ajax(); 133 122 new Admin\Rbbqp_Settings(); 134 123 } 135 124 136 125 new Inc\Rbbqp_Product_Helper(); 137 138 126 if ( is_cart() ) { 139 127 new Inc\Rbbqp_Cart_Helper();
Note: See TracChangeset
for help on using the changeset viewer.