Jump to content

Lyse

Members
  • Content Count

    35
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Lyse

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. In Canada we do have a complex tax system. Both WooCommerce and The Wholesale Suite Prices plugin do not integrate that complexity. So special tax rate tables and supporting functions had to be created to work around taxes and their exemptions per customer role. The shipping methods case is as a result of my client offering reduced flat shipping rates for wholesale customers only reaching membership purchasing levels. The Wholesale plugin allows mapping of the shipping methods by roles, however I would have to map all of the existing shipping methods for each wholesale role (15 * 7 shipping methods). The developer won't help with creating a function to do this more efficiently. To create the rates and methods for each customer would require development that I can't do myself. So I revert to using functions to work around the specific requirements. The data structure is MYSQL with tables.
  2. I'm so sorry, but I thought we were close to making this work. But thank you for all of your help.
  3. The testing was done after I removed the commented code. I simply recopied the arrays from the one that worked yesterday. I'm still no sure what "(" I was missing, but it works well now. I get other parsing errors/notices about code following the arrays. On my checkout page I see these two notices: Notice: Undefined variable: current_user in /nas/content/staging/silviafindings/wp-content/themes/enfold-child/functions.php on line 723Notice: Trying to get property 'ID' of non-object in /nas/content/staging/silviafindings/wp-content/themes/enfold-child/functions.php on line 723 In the PHP checker I see this: PHP Syntax Check: Parse error: syntax error, unexpected '$wwp_wholesale_role' (T_VARIABLE) in your code on line... for the line $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole();
  4. I just retested the array and it now works with no parse errors.
  5. I do agree that it's much easier to see and follow the code when it's indented and outdented. I used a code snippet from someone else to accomplish what I wanted and the fact that I'm not too proficient in PHP I do not date to change any thing, most particularly the structure. I have used your suggestion through this one and it's clearer now. Here's the revised code snippet with line 655 commented out with the parse error. /* HIDE WHOLESALE PREMIUM & UNION SHIPPING METHODS FROM ALL OTHER ROLES */ /* Hide specific shipping methods for specific wholesale roles */ add_filter( 'woocommerce_package_rates', function( $shipping_rates ) { // User role and shipping method ID to hide for the user role $role_shipping_method_arr = array ( 'retail' => array ( 'customer' => array  /*Parse error: syntax error, unexpected '' (T_STRING), expecting '(' */ 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)'  ), 'customer_pst_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'customer_tax_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ) ), 'wholesale' => array ( 'wholesale_customer' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'wholesale_pst_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'wholesale_tax_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_silver' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_silver_pst_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_silver_tax_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_gold' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_gold_pst_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_gold_tax_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ) ) ); // Getting the current user role $curr_user = wp_get_current_user(); $curr_user_data = get_userdata($current_user->ID); // Wholesale Suite Roles if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) { $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance(); $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); // Loop through the user role and shipping method pair foreach( $role_shipping_method_arr as $role => $shipping_methods_to_hide ) { // Check if defined role exist in current user role or not if( in_array( $role, $current_user->roles)) { // Loop through all the shipping rates foreach( $shipping_rates as $shipping_method_key => $shipping_method ) { $shipping_id = $shipping_method->get_id(); // Unset the shipping method if found if( in_array( $shipping_id, $shipping_methods_to_hide) ) { unset($shipping_rates[$shipping_method_key]); } } } } } return $shipping_rates; });
  6. I have add the array into my code snippet but get a Parse error: syntax error, unexpected '' (T_STRING), expecting '(' in /nas/content/staging/silviafindings/wp-content/themes/enfold-child/functions.php on line 655. Line 655 is in the customer array 'Silvia Premium Standard Shipping (Tracking Service)', Here's the code snippet: /* HIDE WHOLESALE PREMIUM & UNION SHIPPING METHODS FROM ALL OTHER ROLES */ /* Hide specific shipping methods for specific wholesale roles */ add_filter( 'woocommerce_package_rates', function( $shipping_rates ) { // User role and shipping method ID to hide for the user role $role_shipping_method_arr = array ( 'retail' => array ( 'customer' => array  ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)'  ), 'customer_pst_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'customer_tax_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ) ), 'wholesale' => array ( 'wholesale_customer' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'wholesale_pst_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'wholesale_tax_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_silver' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_silver_pst_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_silver_tax_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_gold' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_gold_pst_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), 'ws_silvia_gold_tax_exempt' => array ( 'Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ) ) ); // Getting the current user role $curr_user = wp_get_current_user(); $curr_user_data = get_userdata($current_user->ID); // Wholesale Suite Roles if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) { $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance(); $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); // Loop through the user role and shipping method pair foreach( $role_shipping_method_arr as $role => $shipping_methods_to_hide ) { // Check if defined role exist in current user role or not if( in_array( $role, $current_user->roles) ) { // Loop through all the shipping rates foreach( $shipping_rates as $shipping_method_key => $shipping_method ) { $shipping_id = $shipping_method->get_id(); // Unset the shipping method if found if( in_array( $shipping_id, $shipping_methods_to_hide) ) { unset($shipping_rates[$shipping_method_key]); } } } } } return $shipping_rates; });
  7. This is what I get: Array is Array ( [retail] => Array ( [customer] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [customer_pst_exempt] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [customer_tax_exempt] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) ) [wholesale] => Array ( [wholesale_customer] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [wholesale_pst_exempt] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [wholesale_tax_exempt] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [ws_silvia_silver] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [ws_silvia_silver_pst_exempt] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [ws_silvia_silver_tax_exempt] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [ws_silvia_gold] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [ws_silvia_gold_pst_exempt] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) [ws_silvia_gold_tax_exempt] => Array ( [0] => Silvia Premium Standard Shipping (Tracking Service) [1] => Silvia Union Standard Shipping (Tracking Service) ) ) )
  8. Think I've got them all now.... $role_shipping_method_arr = array( ['retail'] = array ( ['customer'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['customer_pst_exempt'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['customer_tax_exempt'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), ['wholesale'] = array ( ['wholesale_customer'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['wholesale_pst_exempt'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['wholesale_tax_exempt'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_silver'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_silver_pst_exempt'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_silver_tax_exempt'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_gold'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_gold_pst_exempt'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_gold_tax_exempt'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ) );
  9. So this is now what my arrays structure looks like: $role_shipping_method_arr = array( ['retail'] = array ( ['customer'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['customer_pst_exempt'] array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['customer_tax_exempt'] array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' ), ['wholesale'] = array ( ['wholesale_customer'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['wholesale_pst_exempt'] = array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['wholesale_tax_exempt'] array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_silver'] array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_silver_pst_exempt'] array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_silver_tax_exempt'] array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_gold'] array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_gold_pst_exempt'] array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)', ['ws_silvia_gold_tax_exempt'] array('Silvia Premium Standard Shipping (Tracking Service)', 'Silvia Union Standard Shipping (Tracking Service)' );
  10. It makes a lot of sense not to duplicate keys... So like this... $role_shipping_method_arr = array( $arr['retail'] ["customer"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"); ["customer_pst_exempt"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"); ["customer_tax_exempt"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"); $arr['wholesale'] ["wholesale_customer"] = array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"); ["wholesale_pst_exempt"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)");  ["wholesale_tax_exempt"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"); ["ws_silvia_silver"][0] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"); ["ws_silvia_silver_pst_exempt"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"); ; ["ws_silvia_silver_tax_exempt"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)");  ["ws_silvia_gold"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"); ["ws_silvia_gold_pst_exempt"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)");  ["ws_silvia_gold_tax_exempt"] array( "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)");
  11. Here's how I understood your last comments: $role_shipping_method_arr = array( $arr['retail'] ["customer"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["customer_pst_exempt"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["customer_tax_exempt"] = "Silvia Premium Standard Shipping (Tracking Service)"; ["customer"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1]; ["customer_pst_exempt"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1]; ["customer_tax_exempt"[0]] = "Silvia Union Standard Shipping (Tracking Service)"[1]; $arr['wholesale'] ["wholesale_customer"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["wholesale_pst_exempt"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["wholesale_tax_exempt"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["ws_silvia_silver"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["ws_silvia_silver_pst_exempt"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["ws_silvia_silver_tax_exempt"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["ws_silvia_gold"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["ws_silvia_gold_pst_exempt"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["ws_silvia_gold_tax_exempt"][0] = "Silvia Premium Standard Shipping (Tracking Service)"[1]; ["wholesale_customer"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1]; ["wholesale_pst_exempt"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1]; ["wholesale_tax_exempt"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1]; ["ws_silvia_silver"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1]; ["ws_silvia_silver_pst_exempt"][0] = Silvia Union Standard Shipping (Tracking Service)"[1]; ["ws_silvia_silver_tax_exempt"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1]; ["ws_silvia_gold"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1]; ["ws_silvia_gold_pst_exempt"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1]; ["ws_silvia_gold_tax_exempt"][0] = "Silvia Union Standard Shipping (Tracking Service)"[1];
  12. So I've added the quotes for the string values. I show two shipping methods as values for each key customer. Here's the updated code: $arr['retail'] ["customer"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["customer_pst_exempt"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["customer_tax_exempt"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; $arr['wholesale'] ["wholesale_customer"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["wholesale_pst_exempt"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["wholesale_tax_exempt"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["ws_silvia_silver"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["ws_silvia_silver_pst_exempt"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["ws_silvia_silver_tax_exempt"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["ws_silvia_gold"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["ws_silvia_gold_pst_exempt"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)"; ["ws_silvia_gold_tax_exempt"] = "Silvia Premium Standard Shipping (Tracking Service)", "Silvia Union Standard Shipping (Tracking Service)";
  13. So my first two arrays would look like this" $arr['retail'] [customer] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [customer_pst_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [customer_tax_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [ws_silvia_gold] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [ws_silvia_gold_pst_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [ws_silvia_gold_tax_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); $arr['wholesale'] [wholesale_customer] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [wholesale_pst_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [wholesale_tax_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [ws_silvia_silver] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [ws_silvia_silver_pst_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [ws_silvia_silver_tax_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [ws_silvia_gold] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [ws_silvia_gold_pst_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service); [ws_silvia_gold_tax_exempt] = Silvia Premium Standard Shipping (Tracking Service), Silvia Union Standard Shipping (Tracking Service);
  14. And what would the arrays look like. I'm no proficient in PHP enough working with arrays to create this level of code. Can you help in any way?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.