• Resolved shayed

    (@shayed)


    hi bro is it possible when a buyer add a product to his cart that click will direct him to seller shop page aswell?
    note i am using a code where customer can buy from one seller at a time

    add_action( 'woocommerce_add_to_cart_validation', function( $is_allow, $product_id, $quantity ) {
    	$product = get_post( $product_id );
    	$product_author = $product->post_author;
    
    	//Iterating through each cart item
    	foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    		$cart_product_id = $cart_item['product_id'];
    		$cart_product = get_post( $cart_product_id );
    		$cart_product_author = $cart_product->post_author;
    		if( $cart_product_author != $product_author ) {
    			$is_allow = false;
    			break;
    		}
    	}
    
    	if( !$is_allow ){
    		// We display an error message
    		wc_clear_notices();
    		wc_add_notice( __( " one seller at a time!", "wcfm-ecogear" ), 'error' );
    	}
    	
    	return $is_allow;
    }, 50, 3 );
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author WC Lovers

    (@wclovers)

    when a buyer add a product to his cart that click will direct him to seller shop page aswell?

    – Where it’s redirecting now?

    note i am using a code where customer can buy from one seller at a time

    – No code required for this. There has setting for this at WCFM Admin Setting – Order Setting – https://ibb.co/f0LBs1p

    Thread Starter shayed

    (@shayed)

    I mean when a customer adds a product from woocommerce it should redirect to seller store page. Lets say customers search by biryani in woocommerce page n biryanies from different sellers come out n buyers click add to cart then briyani from x seller added to cart n seller redirect to x seller home page.

    Plugin Author WC Lovers

    (@wclovers)

    Understand. Add this snippet to your site –

    add_filter( 'woocommerce_add_to_cart_redirect', function( $url, $product ) {
    	if( $product && is_object( $product ) && method_exists( $product, 'get_id' ) && function_exists( 'wcfm_get_vendor_id_by_post' ) ) {
    		$vendor_id = wcfm_get_vendor_id_by_post( $product->get_id() );
    		if( $vendor_id && function_exists( 'wcfmmp_get_store_url' ) ) {
    			$url = wcfmmp_get_store_url( $vendor_id );
    		}
    	}
    	return $url;
    }, 500, 2 );

    Add custom code(s) to your child theme’s functions.php
    In case you do not have child theme then add those using this plugin –?https://www.ads-software.com/plugins/code-snippets/

    Thread Starter shayed

    (@shayed)

    Hi thank you. Sorry to say it only works from single product page. From search result page it just adds to cart. Any idea whats wrong? i used oceanwp theme.

    Plugin Author WC Lovers

    (@wclovers)

    Enable this setting option from WooCommerce – Setting – Products – https://ibb.co/dkr49wG

    Thread Starter shayed

    (@shayed)

    Thanks bro i also think of that. Bro just want to know when do your products go on sales? like to buy few for my single site.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘cart’ is closed to new replies.