• Resolved sketchuprzr

    (@sketchuprzr)


    Hello,
    I don’t want more than one seller’s product to appear on the cart page.
    Because I use a different payment channel for each seller. Therefore, I want to list only one seller’s products in the cart.

    I am using the Woodmart theme.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WebWizards

    (@webwizardsdev)

    To achieve that, you can add this PHP code snippet to your site:

    // Add a filter to check the cart before proceeding to checkout
    add_action( 'woocommerce_check_cart_items', 'check_cart_authors' );
    
    function check_cart_authors() {
        // Initialize an empty array to store author IDs
        $author_ids = array();
    
        // Loop through each item in the cart
        foreach ( WC()->cart->get_cart() as $cart_item ) {
            // Get the author ID of the current item
            $author_id = get_post_field( 'post_author', $cart_item['product_id'] );
    
            // If the author ID is not in the array, add it
            if ( ! in_array( $author_id, $author_ids ) ) {
                $author_ids[] = $author_id;
            }
        }
    
        // If there is more than one author in the cart, show an error message and prevent checkout
        if ( count( $author_ids ) > 1 ) {
            wc_add_notice( __( 'You cannot checkout because the cart contains products from different vendors.', 'woocommerce' ), 'error' );
            // Remove the "Proceed to Checkout" button
            remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
        }
    }

    It will show an error on the cart page if there are multiple vendors:

    https://prnt.sc/QvNB_x5PKinf

    The code can be added to functions.php or to any snippets plugin.

    Also, to remove the standard message there saying “The products in your cart are sold by multiple different vendor partner….” you can go to MarketKing -> Settings -> Language & Text, and delete it.

    Thread Starter sketchuprzr

    (@sketchuprzr)

    Thanks! Worked.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multi Vendor Products on cart page’ is closed to new replies.