• Hi,

    is it possible to give users permission on the frontend to export orders only with specific products?
    I was able to put a button on the frontend which exports all orders with the help of another question:

    <form method="get" action="/wp-admin/admin-ajax.php">
    <input type="hidden" name="action" value="order_exporter">
    <input type="hidden" name="method" value="run_one_job">
    <input type="hidden" name="profile" value="now">
        <input type="submit" name="exportAllOrders" id="exportAllOrders" value="Export">
    </form>

    So for example I have 3 products, and I want user1 to be able to export product 1 and 2, user2 to export only product 1 etc.
    Thanks,
    Tamas

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello Tamas

    do you want to allow users export only own products ?

    what plugin do you use to assign users to products ?

    thanks, Alex

    • This reply was modified 6 years, 12 months ago by algol.plus.
    Thread Starter icecube018

    (@icecube018)

    Hello Alex,

    currently none. How can I do the assignment? And sorry if that’s a silly question.

    Tamas

    Plugin Author algol.plus

    (@algolplus)

    ok, let’s ask another question.
    do you want to hard-code product list for each user ?

    Thread Starter icecube018

    (@icecube018)

    Yes, that’s all right for me.

    Plugin Author algol.plus

    (@algolplus)

    Please, add following code to section “Misc Settings” and tweak product lists

    add_filter('woe_settings_validate_defaults', function($settings){
    	$user_id = get_current_user_id();
    	$user_products = array(
    		// format is user_id=>array(product_id,product_id,product_id,),
    		1=>array(20,21,22),
    		12=>array(2,8),
    	);
    	
    	if( isset($user_products[$user_id])){
    		$settings["products"] = $user_products[$user_id];
    		$settings["all_products_from_order"] = 0; // to see only selected products
    	} else {
    		$settings["products"] = array(-1); // user will get empty file 
    	}
    	return $settings;
    });
    
    Thread Starter icecube018

    (@icecube018)

    This works perfectly!
    I can’t thank you enough for your fast and helpful reply! You are awesome!
    And just out of curiosity, what should I do if I don’t want to hardcode the product list? It’s all right if you don’t have time to explain this, your answer was really helpful.
    Thanks,
    Tamas

    Plugin Author algol.plus

    (@algolplus)

    hi Tamas

    you can assign users to products, try this code

    if ( post_type_exists( 'product' ) ) {
    add_post_type_support( 'product', 'author' );
    }

    more details
    https://publishpress.com/blog/add-authors-woocommerce-products/

    Plugin Author algol.plus

    (@algolplus)

    and you must modify my code , to pull assigned product IDs to $settings[“products”].

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Allow user to export certain products only’ is closed to new replies.