• Resolved cronopium

    (@cronopium)


    I build a shop for B2C clients and B2B clients and use the catalog enquiry for disabling prices for B2C.
    In the exclusion definitions I am surprised there is no possibility to use user role for exclusion.
    If I could use user role for exclusion I could configure a automatic process … all clients with b2b user role can see the prices and use the order …
    you only use a user list for exclusion – this would need every b2b client put in this list.
    if you don’t give the possibility for user role in backend, maybe you can help me with a code for filtering in the function php – it would be very helpful.

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Kindly use this code snippet :

    function user_role_exclude_catalog(){
    global $WC_Woocommerce_Catalog_Enquiry;
    $current_user = wp_get_current_user();
    if($WC_Woocommerce_Catalog_Enquiry){
    if(in_array('your_restricted_user_role', $current_user->roles)){
    remove_action('woocommerce_single_product_summary', array($WC_Woocommerce_Catalog_Enquiry->frontend,'add_form_for_enquiry_without_popup'),100);
    remove_action('woocommerce_single_product_summary', array($WC_Woocommerce_Catalog_Enquiry->frontend,'add_form_for_enquiry'),100);
    }else{
    $WC_Woocommerce_Catalog_Enquiry->frontend->init_catalog();
    }
    }
    }
    add_action('init', 'user_role_exclude_catalog', 999);

    Let us know if you have any further query.

    Thread Starter cronopium

    (@cronopium)

    thank you for the fast solution ??

    Thread Starter cronopium

    (@cronopium)

    Hello, if I use this code I lost the dashboard …
    in debug I get this – maybe you understand where the problem is:

    `Fatal error: Uncaught Error: Call to a member function init_catalog() on null in /html/wordpress/wp-content/themes/infinity-pro/functions.php:326 Stack trace: #0 /html/wordpress/wp-includes/class-wp-hook.php(298): user_role_exclude_catalog(”) #1 /html/wordpress/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(false, Array) #2 /html/wordpress/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /html/wordpress/wp-settings.php(448): do_action(‘init’) #4 /html/wordpress/wp-config.php(115): require_once(‘/html/wordpress…’) #5 /html/wordpress/wp-load.php(37): require_once(‘/html/wordpress…’) #6 /html/wordpress/wp-admin/admin.php(31): require_once(‘/html/wordpress…’) #7 /html/wordpress/wp-admin/post.php(12): require_once(‘/html/wordpress…’) #8 {main} thrown in /html/wordpress/wp-content/themes/infinity-pro/functions.php on line 326

    Sorry, for this. Kindly use changes the hook name init to wp and let us know whether this fixed the error.

    Awaiting for your confirmation.

    Thread Starter cronopium

    (@cronopium)

    After change I get the Dashboard but don’t products or woo commerce orders anymore

    function user_role_exclude_catalog(){
    global $WC_Woocommerce_Catalog_Enquiry;
    $current_user = wp_get_current_user();
    if($WC_Woocommerce_Catalog_Enquiry){
    if(in_array('your_restricted_user_role', $current_user->roles)){
    remove_action('woocommerce_single_product_summary', array($WC_Woocommerce_Catalog_Enquiry->frontend,'add_form_for_enquiry_without_popup'),100);
    remove_action('woocommerce_single_product_summary', array($WC_Woocommerce_Catalog_Enquiry->frontend,'add_form_for_enquiry'),100);
    }else{
    $WC_Woocommerce_Catalog_Enquiry->frontend->wp_catalog();
    }
    }
    }
    add_action('wp', 'user_role_exclude_catalog', 999);

    The error code:

    Fatal error: Uncaught Error: Call to a member function wp_catalog() on null in /html/wordpress/wp-content/themes/infinity-pro/functions.php:306 Stack trace: #0 /html/wordpress/wp-includes/class-wp-hook.php(298): user_role_exclude_catalog(Object(WP)) #1 /html/wordpress/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array) #2 /html/wordpress/wp-includes/plugin.php(515): WP_Hook->do_action(Array) #3 /html/wordpress/wp-includes/class-wp.php(746): do_action_ref_array('wp', Array) #4 /html/wordpress/wp-includes/functions.php(955): WP->main(Array) #5 /html/wordpress/wp-admin/includes/post.php(1072): wp(Array) #6 /html/wordpress/wp-admin/includes/class-wp-posts-list-table.php(142): wp_edit_posts_query() #7 /html/wordpress/wp-admin/edit.php(180): WP_Posts_List_Table->prepare_items() #8 {main} thrown in /html/wordpress/wp-content/themes/infinity-pro/functions.php on line 306

    Just change the hook name and not the function name init_catalog() to wp_catalog().

    For further assistance please see this screenshot : https://drive.google.com/a/dualcube.com/file/d/0Bx3S5WbEjHvpWE10aHhFT3NlZXM/view?usp=drivesdk

    Thread Starter cronopium

    (@cronopium)

    I’m so sorry…
    of course – first I only did change this but Error again. After I tried other.
    Then I did try again to exclude a standard role ‘subscriber’ instead of my own but the same …

    //* Catalog Enquiry user role
    function user_role_exclude_catalog(){
    global $WC_Woocommerce_Catalog_Enquiry;
    $current_user = wp_get_current_user();
    if($WC_Woocommerce_Catalog_Enquiry){
    if(in_array('subscriber', $current_user->roles)){
    remove_action('woocommerce_single_product_summary', array($WC_Woocommerce_Catalog_Enquiry->frontend,'add_form_for_enquiry_without_popup'),100);
    remove_action('woocommerce_single_product_summary', array($WC_Woocommerce_Catalog_Enquiry->frontend,'add_form_for_enquiry'),100);
    }else{
    $WC_Woocommerce_Catalog_Enquiry->frontend->init_catalog();
    }
    }
    }
    add_action('wp', 'user_role_exclude_catalog', 999);

    Fatal error: Uncaught Error: Call to a member function init_catalog() on null in /html/wordpress/wp-content/themes/infinity-pro/functions.php:306 Stack trace: #0 /html/wordpress/wp-includes/class-wp-hook.php(298): user_role_exclude_catalog(Object(WP)) #1 /html/wordpress/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array) #2 /html/wordpress/wp-includes/plugin.php(515): WP_Hook->do_action(Array) #3 /html/wordpress/wp-includes/class-wp.php(746): do_action_ref_array('wp', Array) #4 /html/wordpress/wp-includes/functions.php(955): WP->main(Array) #5 /html/wordpress/wp-admin/includes/post.php(1072): wp(Array) #6 /html/wordpress/wp-admin/includes/class-wp-posts-list-table.php(142): wp_edit_posts_query() #7 /html/wordpress/wp-admin/edit.php(180): WP_Posts_List_Table->prepare_items() #8 {main} thrown in /html/wordpress/wp-content/themes/infinity-pro/functions.php on line 306

    Thread Starter cronopium

    (@cronopium)

    do you have no other idea? it would be so helpful if I could work with user role…

    do a woocommerce-catalog-enquiry plugin active check within function before the codes and let us know the result.

    Thanks for help, but unfortunately me english is not good enough – I’m not really understanding what I i have to do to get the result you need.

    Just now I see another Plugin with the same functionality has the role exclusion as standard (seems for me it is the much better way because it is not practicable a lot of customers exclude by hand) …
    but I would like to go on with your plugin – it works for me, I’m only missing the role excusing.
    maybe you will integrate in future in your plugin?

    Hi @bpamedia, thanks for getting in touch with us.

    We have forwarded this request to our development team, they will take a further decision over this.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Exclusion Settings’ is closed to new replies.