Untitled

 avatar
unknown
plain_text
2 years ago
1.1 kB
3
Indexable
add_action('template_redirect', function(){
	$store_url = get_query_var('vendorid');
	$users = get_users(array(
		'meta_key'     => 'marketking_store_url',
		'meta_value'   => $store_url,
		'meta_compare' => '=',
	));

	if (!empty($users)){
		$vendor_id = $users[0]->ID;	
		
		$set = false;
		if(!isset($_COOKIE['woocommerce_recently_viewed_1'])){
			$set = true;
		} else {
			if (marketking()->get_product_vendor($_COOKIE['woocommerce_recently_viewed_1']) != $vendor_id){
				$set = true;
			}
		}
		if ($set){
			// get a random vendor product
			$products = get_posts( array( 
				'post_type' => 'product',
				'numberposts' => 5,
				'post_status'    => 'any',
				'fields'    => 'ids',
				'author'	=> $vendor_id
			));
			$setproduct = '';
			foreach ($products as $productid){
				if (get_post_meta($productid, 'marketking_is_product_standby', true) !== 'yes'){
					$setproduct = $productid;
					break;
				}
			}

			setcookie("woocommerce_recently_viewed_1", $setproduct, time()+31536000, '/'); 
			global $wp;
			wp_redirect(home_url( $wp->request ));
		}

	} 
});
Editor is loading...
Leave a Comment