skip to Main Content

I use Dokan and WooCommerce. I want to hide the add to cart buttons on the products, so sellers do not have payment set up in their seller dashboard.

I have the following function, but it does not work:

add_filter( 'woocommerce_is_purchasable','woocommerce_available_payment_gateways' function( $show_cart, $product, $available_payment_gateways ) {

    $seller_id = get_post_field('post_author', $product->get_id());

    if(isset($available_payment_gateways( $seller_id )) {
        $show_cart = true;
    } else {
        $show_cart = false;
    }
    return $show_cart;
}, 10, 2 );

2

Answers


  1. Chosen as BEST ANSWER

    Good morning,

    we found that dokan simply displays a message at the end when the customer enters his card to indicate that payment for the product is not possible because the seller has not entered a payment method. We would rather hide the add to cart button from visitors on products from sellers who have not entered a payment method in their seller dashboard.


  2. There are a lot of mistakes in your code, and your question is not very clear. So I guess that you want to avoid a seller to be able of purchasing its own products.

    Then try the following:

    add_filter('woocommerce_is_purchasable', 'filter_woocommerce_is_purchasable', 10, 2 );
    function filter_woocommerce_is_purchasable( $purchasable, $product ) {
        $seller_id = get_post_field('post_author', $product->get_id());
    
        if( get_current_user_id() == $seller_id ) {
            $purchasable = false;
        }
    
        return $purchasable;
    }
    

    Code goes in function.php file of your active child theme (or active theme). It should work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search