Home Support Extensions Marketplace Is there a way to apply marketplace to specific categories only?

Is there a way to apply marketplace to specific categories only?

  • Author
    Posts
  • nandrews283

    Hello,

    I would like the ability to apply the “buy now” button to specific categories only. Is there a way to make it disappear for certain categories?

    Thanks!

    ihor developer

    There’s no option for this at the moment, but it’s on the roadmap. If this works for you, I can provide a code snippet that will display the price field for specific categories only, but you’ll have to set category IDs manually.

    nandrews283

    I was moreso looking to just get rid of the buy now button from certain categories and leave the price. Is there a snippet for this?

    Thanks!

    ihor developer

    Please try using this one, replace 1, 2, 3 with category IDs you want to exclude:

    add_filter(
    	'hivepress/v1/templates/listing_view_page',
    	function( $blocks, $template ) {
    
    		// Get listing.
    		$listing = $template->get_context( 'listing' );
    
    		if ( $listing && array_intersect( [ 1, 2, 3 ], (array) $listing->get_categories__id() ) ) {
    			$blocks = hivepress()->helper->merge_trees(
    				[ 'blocks' => $blocks ],
    				[
    					'blocks' => [
    						'listing_buy_form' => [
    							'type' => 'content',
    						],
    					],
    				]
    			)['blocks'];
    		}
    
    		return $blocks;
    	},
    	1000,
    	2
    );
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.