Show Buy Now button depending on user type

Hello friends,

I want to use 2 different user types: Individual & Company
For individual I don’t want my listings to have the buy button but for companies to be there.

Is there any option to do that ?

Thanks !

Hi,
Unfortunately there’s no option to make this button dependent on the user type, but you can make the price optional using this code snippet Make the price field optional for marketplace listings #hivepress #marketplace · GitHub Then if the price is not set, the Buy Now button will be hidden.

Ok, would be possible on future updates, please ? I think is a important feature because I made a website where you can sell with crypto and as individual you can’t, legally, sell with crypto, just companies.

There is any other way to control this somehow ? Like, maybe you can make me a snippet code with an php IF user category is individual, then no pay button, if user category is Company, then show button ?

I made it with a snippet where I add a custom css class to hide the button if the user is in category individual… but I found out that post_type: hp_vendor has no category, the category is exerpt text…

function bmk_category( $data ) {
	preg_match_all( '/(?<=Category:\s)(.+)\;?/', $data, $matches);
	//print_r($matches);
	return $matches[1][0];
}
add_filter(
	'hivepress/v1/forms/listing_buy',
	function( $attributes ) {
		//$attributes["button"]["attributes"]["class"][]="hp-hidden-user_individual";
		$plm = wp_get_current_user();
		//print_r($plm);
 		$vendors = get_posts(array( 'post_type' => 'hp_vendor', 'author' => $plm->data->ID ));
		if(count($vendors) == 1) {
			$bmktype = bmk_category( $vendors[0]->post_excerpt );
			if($bmktype == "Individual.") {
				$attributes["button"]["attributes"]["class"][]="hp-hidden-user_individual";
			}
			//print_r($bmktype);
		}
		//print_r($vendors);	
		return $attributes;
	},
	1000
);

I don’t recommend this solution but works for now.

Yes, it’s possible with customizations, if you’re familiar with PHP basics please try the hivepress/v1/templates/listing_view_page filter/blocks filter, you can remove the listing_buy_form block depending on any context values.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.