提交后的表单重定向

时间:2019-03-29 13:00:18

标签: wordpress redirect http-status-code-404

发布自定义帖子后,我正在运行wp_redirect来重定向用户。

我添加了另一个重定向,以提交特定表单后重定向到购物车页面。提交表单后,它将重定向到404页面。

它的行为很奇怪-它可以处理到最后一个带有wp_redirect的IF语句...

看起来有些其他重定向正在执行此操作,但是没有其他重定向。模板显示“在IF之前”回显,单击提交后将重定向到404页面。

<form method="post" action="">
            <div class="renewal_field_wrapper">
                <div class="business_explain_floated">Select time period for your advertisement:</div>
                <div class="renewal_period">
                    <select name="advertisement_length">
                        <option value="30">1 Month (30 days)</option>
                        <option value="60">2 Months (60 days)</option>
                        <option value="90">3 Months (90 days)</option>
                        <option value="120">4 Months (120 days)</option>
                        <option value="150">5 Months (150 days)</option>
                        <option value="180">6 Months (180 days)</option>
                    </select>
                </div>
                <div class="renewal_check">
                    <input type="checkbox" name="confirm" value="Confirm" required> I confirm this will renew my advertisement called <strong><?php echo get_the_title($ad_id); ?></strong>
                </div>
                <div class="renewal_btn">
                    <input type="hidden" name="post_type" value="<?php echo $type; ?>" />
                    <input type="hidden" name="identifier" value="<?php echo $ad_id; ?>" />
                    <input type="submit" id="renewal_submit" value="NEXT">
                </div>
            </div>
            </form>

function checkout_redirect() {
    if( is_page( 'add-new-advertisement' )) {
        post_advertisement();
    }
    if(is_page('advertisement-renewal')) {
        $ad_id = $_GET['ad_id'];
        $post_type = get_post_type($ad_id);

        if($post_type == 'trainer_ads') {

            $advertisement_type = 'trainer_advertisement';
            $advertisement_length = $_POST['advertisement_length'];
            $_SESSION['advertisement_length'] = $advertisement_length;
            $_SESSION['advertisement_type'] = $advertisement_type;

            $quantity = $advertisement_length / 30;
            $_SESSION['quantity'] = $quantity;
            $_SESSION['ad_length'] = $advertisement_length;
            echo 'before IF';

            if($_POST['identifier']) {              
                //Price set in Website Settings pages
                //Add advertisment to cart and modify price
                add_trainer_ad_to_cart();
                wp_redirect(home_url('/cart/'));

                die;
            }
        }
    }
}
add_action( 'template_redirect', 'checkout_redirect' );

0 个答案:

没有答案
相关问题