I’m building a custom extension that adds an extra step after editing a listing: the user should be redirected to a custom page (/select-options/) to choose from a list of available packages.
What I’ve implemented so far:
A custom HivePress route listing_edit_options_page (similar to listing_submit_page)
A custom template with a block-based layout showing available options
The issue:
The listing edit form on /account/listings/{id}/ uses AJAX, so wp_safe_redirect() or similar server-side solutions have no effect.
The “Changes have been saved.” message appears, but the user stays on the same page.
My question:
What’s the recommended way to redirect a user to a custom route after editing a listing via AJAX, while following HivePress architecture (routes, templates, blocks, etc.)?
I do not think it will work like you want. The standard form redirects to an endpoint and this is not somtehing you can change. I build a multiustep add listing form, and nothing of the original could be recycled because the way it is structured, except from the original submit end-poind.
You can set the data-redirect=“” attribute on a form wichh submits to a rest endpoint by means of AJAX and it will redirect to the specified url, but if i remember correctly the native add /edit listing form has the attribute alredy set to “true”.
You have to keep in mind that the submit to the original end-point changes to status of the listing, sends email and handles moderation (if enabled). So you will have to either:
duplicate the code (which is not recommended considering if an update changes anything in the workflow, your code does not, or
after your custom select options page redirect to the original submit end-poind.
If you created a custom route and template, you can try adding this route to the “listing_submit” menu (“hivepress/v1/menus/listing_submit” hook), the listing submission process goes through all the items available in this menu.
Thanks a lot for your clear and helpful explanation — that makes perfect sense now!
I really appreciate your guidance and will test this approach using the listing_submit menu. It’s great to have such a well-structured and extensible system to work with.
I had already implemented my custom route and template by replicating the logic used in the Paid Listings extension for new listing submission. Everything works fine on that side.
As suggested, I also tried adding my custom route to the listing_submit menu using the hivepress/v1/menus/listing_submit hook. The route appears correctly in the menu structure.
However, my custom flow is not being triggered — instead, the listing update still happens via AJAX, and there’s no redirection to the package selection page.
It seems that the standard edit form at /account/listings/{id}/ is still being handled by HivePress’s AJAX logic, and my route is bypassed.
Do you have any recommendation for disabling the AJAX behavior or overriding the edit form submission so the process follows the new flow and triggers my custom route?
Please make sure that you added it the same way as Paid Listings adds its “listing_submit_package_page” route to the “hivepress/v1/menus/listing_submit” menu, if you added it with the same “_order” then after the listing draft is saved via AJAX, the form redirects users to the next page in the menu automatically. Unfortunately I can’t advice on overriding the default AJAX form behavior as this would require advanced customizations.
Thanks for your reply. I understand now that the listing submission flow uses the listing_submit menu to automatically redirect between steps, while the edit form is handled via AJAX and doesn’t provide a similar mechanism.
For now, I will put this evolution on hold and keep the current behavior, as overriding the AJAX workflow would indeed require deeper customizations.