Okay
  Public Ticket #3135435
Limit vendor group csv product import and export columns
Closed

Comments

  •  3
    vtwigge1000 started the conversation

    Hi

    Is it possible to limit (programmatically) the CSV product import and export columns based on a specific vendor group?

    I have looked at this github repository for guidelines in terms of customisation and can only see the possibility of adding custom columns and nothing on removing/disabling columns. https://github.com/woocommerce/woocommerce/wiki/Product-CSV-Importer-&-Exporter#adding-custom-export-columns-developers

    The reason for this is that we want to limit the control a vendor group has over what product fields they can edit/import in bulk.

    Any suggestions that can point me in the right direction would be greatly appreciated.


    Regards

    Victor

  •  1,833
    WebWizards replied

    Hi Victor,

    To remove columns during export for vendors, you can use this sample code snippet:

    add_filter( 'woocommerce_product_export_product_default_columns','change_columns_export', 10, 1); 
    add_filter( 'woocommerce_product_export_column_names','change_columns_export', 10, 1); 
    function change_columns_export($columns){
        if (marketking()->is_vendor(get_current_user_id())){
            unset($columns['vendor_id']);
        }
        return $columns;
    }
    

    What this snippet does is that it removes the vendor_id column during export for vendors.

    You would need to look at that $columns variable to see the exact names (Slugs) of each column.


    During import, you can use the following:

    add_filter('marketking_available_options_import', function($columns, $user_id){
                
      return $columns;
    }, 10, 2);
    

    Similarly you can use unset($columns['abc']) to remove a column.


    I want to let you know that we have already tried to remove columns which could be problematic and we put in some protections there. For example we removed columns such as 'Featured', upsells, cross-sells etc.


    Kind regards,

    Stefan

  •  3
    vtwigge1000 replied

    Perfect

    Thank you Stefan