Display of website items

Hello All,

I have a requirement for my ecommerce website where the display of products available depends on the customer group.
Eg Customer A can view product X and Y, but customer B can view only product Y.

Also if the product is out of stock, it should not be displayed on the website, is there a way to automatically unpublish the item?

I have created a custom script but it does not work:

frappe.ui.form.on(‘Website Item’, {
validate: function(frm) {
frappe.call({
method: “frappe.db.get_value”,
args: {
doctype: “Bin”,
filters: { item_code: frm.doc.item_code },
fieldname: [“sum(actual_qty) as total_stock”]
},
callback: function(response) {
const total_stock = response.message ? response.message.total_stock : 0;
if (total_stock <= 0) {
frm.set_value(‘published’, 0);
}
}
});
}
});

Kindly help on these issues.

Kind Regards,