• Resolved cdoher01

    (@cdoher01)


    Hi,

    I would like to redirect the user after then successful submit an advert for publication.

    Is there to use add_filter( “adverts_form_bind”, “forms_api_example_bind_defaults”, 10, 2); to only trigger if the submission is complete?

    Thanks,
    Connor

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    you will not able to redirect the user once the submission is completed because at this point already some content is sent to the browser by the theme and the redirects will not work.

    What you can do is redirect the user when on a [adverts_add] / Preview page he will click the “Publish Listing” button.

    For example, the code below will do that

    
    add_action( "template_redirect", function() {
    
        $action = adverts_request("_adverts_action");
        $post_id = absint( adverts_request( "_post_id" ) );
        
        if($action != "save" || $post_id === 0 ) {
            return;
        }
    
        // Save action was executed you can do redirect below
        wp_redirect( "https://example.com" );
    } );
    

    This will, of course, work best if the Ad is posted for free then you can just update its post_status with wp_update_post() function or if you have some plan to handle the payments on your own, as with this code the user will not see the default success page or the payment form.

    Probably to see how it looks like it would be best to paste the code above in your theme functions.php file and post a new Ad from page with [adverts_add] shortcode.

    Thread Starter cdoher01

    (@cdoher01)

    Hi, okay thank you for that.

    The user flow I am trying to achieve is:
    – User registers in via the /my-account page (on success redirected to adverts add page)
    – fills out advert form (on completion redirected to woo commerce checkout to purchase subscription)
    – user purchases subscription (on purchase success redirected to page where user can finalize/publish advert)
    – user publishes/manages adverts

    How do you think I can best achieve that? It seems that payment flow could be relevant, but not sure if that integrates with woo commerce subscriptions?

    Thank you for you help!
    -Connor

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i think that before wp_redirect( "https://example.com" ); you would need to add the subscription to the user cart and add to the product some meta-information to connect the product to $post_id.

    The WPAdverts WC integration does this like that

    
    $woocommerce->cart->add_to_cart( $product_id, 1, '', '', array(
        'advert_id' => $post_id
    ) );
    

    The $product_id would need to be equal to your subscription product ID. This will add the subscription to the cart so the next step would be to redirect the user to WC checkout when the user can pay for the subscription.

    Finally, you would need to use some hook to activate Ad when payment is received. For example woocommerce_order_status_completed although i am not sure if this will work for subscriptions as well.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘adverts_form_complete filter??’ is closed to new replies.