Join our new community forum for support & discussion

Join Now

Home Support Themes TaskHive List a service without going through the “submit-listing/category/” page

List a service without going through the “submit-listing/category/” page

  • Author
    Posts
  • bromo01

    I’m trying to submit listings selecting a category directly on the “submit-listing/details/” page.
    I already added categories as a listing custom attribute, so I can select them in the details page.
    I can hide the “List a Service” button on the header and add another button targetting directly to the details page.
    The only problem is that if a user which is not logged in tries to submit a listing, after signing in, he is redirected to the “submit-listing/category/” page, instead I would like him to be redirected to the “submit-listing/details/” page.
    I hope I have clearly explained the problem.
    However, I really like the theme and I’m really enjoying it, thank you.

    yevhen developer

    You can try such solution which will add select category attribute to details page and there is no needed in custom category attribute.

    add_filter(
      'hivepress/v1/menus/listing_submit',
      function( $menu ) {
        $menu['items']['listing_submit_category']['_order'] = 10000;
    
        return $menu;
      },
      1000
    );
    
    add_filter(
    	'hivepress/v1/templates/listing_submit_details_page/blocks',
    	function( $blocks, $template ) {
    		return hivepress()->helper->merge_trees(
    					[ 'blocks' => $blocks ],
    					[
    						'blocks' => [
    							'listing_submit_form' => [
    								'footer' => [
    									'form_actions' => [
    										'blocks' => [
    											'listing_category_change_link' => [ 
    												'type' => 'content',
    											],
    										],
    									],
    								],
    							],
    						]
    						
    						
    				]
    				)['blocks'];
    	},
    	1000,
    	2
    );
    
    add_filter(
    	'hivepress/v1/forms/listing_update',
    	function( $form ) {
    		$form['fields']['categories'] = [
    			'multiple' => false,
    			'_order'   => 20,
    		];
    
    		return $form;
    	}
    );
    bromo01

    Thank you very much, it works as I needed.
    I also modified the last part of your code:

    add_filter(
    	'hivepress/v1/forms/listing_update',
    	function( $form ) {
    		$form['fields']['categories'] = [
    			'multiple' => false,
    			'_order'   => 20,
    			'required' => true,
    			'placeholder' => "select a category",
    		];
    
    		return $form;
    	}
    );

    This way the category field is now required.

    Just the last question (sorry!): as you can see I also tried to add a placeholder which appears in the dropdown, but it is not selected. The default selected category is that with the order 1 (even if there is a category with the order set to 0). Can I make the placeholder appear as default value?
    Thank you

    yevhen developer

    It seems to be ok when I test the same snippet locally. Please let me know if this issue persists.

Viewing 4 posts - 1 through 4 (of 4 total)

New Reply

This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.