Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Aelia Currency Switcher for WooCommerce - Filter the orders on the orders list
- * page, showing only the ones with specific currencies depending on users' role.
- *
- * HOW TO USE THIS CODE
- * Add the code to the bottom of your theme's functions.php file (see https://www.skyverge.com/blog/add-custom-code-to-wordpress/).
- * The code will run on the Orders List page, check the user's role, and only show
- * orders the specific currency associated to that role.
- *
- * GPL DISCLAIMER
- * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
- * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
- * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
- * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
- * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
- *
- * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
- */
- add_filter('request', function($vars) {
- global $typenow, $wpdb;
- // Only alter the query on the Orders List page
- if($typenow == 'shop_order') {
- // By default, don't filter orders
- $currency = '';
- // Check if the user can only see GBP orders
- if(current_user_can('see_only_gbp_orders')) {
- $currency = 'GBP';
- }
- // Check if the user can only see EUR orders
- if(current_user_can('see_only_eur_orders')) {
- $currency = 'EUR';
- }
- // Filter orders by currency
- if(!empty($currency)) {
- $vars['meta_query']['relation'] = 'AND';
- // Only show orders in the specific currency
- $vars['meta_query'] = array(
- array(
- 'key' => '_order_currency',
- 'value' => $currency,
- 'compare' => '=',
- ),
- );
- }
- }
- return $vars;
- }, 15 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement