0

I'm going crazy for a few hours, and I need help. Please :) I would like to disable the sale of products added by a specific seller in woocommerce. I use Dokan, a plugin that transforms woocommerce into a market place. This is what I did and that seems to me a good approach: I have created a new role "nonsellingshop" which has the same rights as the default seller role created by Dokan. This role can therefore add products and their price. I would like products added by this specific role can not be purchased, and instead of the add to cart button appears a message saying 'This seller does not offer its products for sale online'. Of course for the sellers not having this role, it is necessary that the sale is possible. It is also necessary that if I change the role of a seller "nonsellingshop" to give it the normal role, the sale becomes possible.

Does anyone have an idea of ​​how I can do this?

Thank you a thousand times in advance for your help

So this what i've done so far (and that doesn't work) :

function get_seller_role_and_hide_cart_button_if_non_seller () { //gets the ID of the post $post_id = get_queried_object_id();

            //gets the ID of the author using the ID of the post
            $author_ID = get_post_field( 'post_author', $post_id );

            //Gets all the data of the author, using the ID
            $authorData = get_userdata( $author_ID );

            //checks if the author has the role of 'subscriber'
            if (in_array( 'boutiquenonvendeuse', $authorData->roles)){
    add_filter( 'woocommerce_is_purchasable', '__return_false'); // DISABLING PURCHASE FUNCTIONALITY AND REMOVING ADD TO CART BUTTON FROM NORMAL PRODUCTS
    remove_action('woocommerce_single_variation', 'woocommerce_single_variation', 10); // REMOVING PRICE FROM VARIATIONS
    remove_action('woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20); // REMOVING ADD TO CART BUTTON FROM VARIATIONS
}

} add_action ('init', 'get_seller_role_and_hide_cart_button_if_non_seller');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.