数据保存后的Woocommrce重定向

时间:2016-09-09 13:05:54

标签: woocommerce shipping

我为发货地址创建了单独的页面,并在表单中也有一些自定义字段。

保存表单数据的代码如下:

<?php
$user_ID = get_current_user_id();
$order_ID = $_GET['ordership'];
if(isset($_POST['save_address_temp']))
{

    update_post_meta( $order_ID, '_shipping_accomodation', $_POST['shipping_accomodation']);
    update_post_meta($order_ID , 'Delivery Date', date("d M, Y", strtotime($_POST['delivery_date'])));
$shipping_firs = update_user_meta($user_ID , 'shipping_first_name', $_POST['shipping_first_name']);
$shipping_last = update_user_meta($user_ID , 'shipping_last_name', $_POST['shipping_last_name']);
$shipping_coun = update_user_meta($user_ID , 'shipping_country', $_POST['shipping_country']);
$shipping_email = update_user_meta($user_ID , 'shipping_email', $_POST['shipping_email']);
//$shipping_phone = update_user_meta($user_ID , 'shipping_phone', $_POST['shipping_phone']);
$shipping_addr1 = update_user_meta($user_ID , 'shipping_address_1', $_POST['shipping_address_1']);
$shipping_addr2 = update_user_meta($user_ID , 'shipping_address_2', $_POST['shipping_address_2']);
$shipping_post = update_user_meta($user_ID , 'shipping_postcode', $_POST['shipping_postcode']);

}
$ddate = get_post_meta($order_ID , 'Delivery Date', true);
$accomodation = get_post_meta($order_ID , '_shipping_accomodation', true);
$shipping_firs = get_user_meta($user_ID , 'shipping_first_name', true);
$shipping_last = get_user_meta($user_ID , 'shipping_last_name', true);
$shipping_coun = get_user_meta($user_ID , 'shipping_country', true);
$shipping_email = get_user_meta($user_ID , 'shipping_email', true);

//$shipping_phone = get_user_meta($user_ID , 'shipping_phone', true);
$shipping_addr1 = get_user_meta($user_ID , 'shipping_address_1', true);
$shipping_addr2 = get_user_meta($user_ID , 'shipping_address_2', true);
$shipping_post = get_user_meta($user_ID , 'shipping_postcode', true);
?>
<link rel='stylesheet' id='datepicker-css'  href='http://example.in/wp-content/plugins/order-delivery-date-for-woocommerce/css/datepicker.css?ver=4.5.3' type='text/css' media='' />
<script language="javascript">
    jQuery( document ).ready( function(){
        //jQuery( "#e_deliverydate" ).attr( "readonly", true );
        var formats = ["MM d, yy","MM d, yy"];
        jQuery.extend( jQuery.datepicker, { afterShow: function( event ) {
            jQuery.datepicker._getInst( event.target ).dpDiv.css( "z-index", 9999 );
            if ( jQuery( "#orddd_lite_number_of_months" ).val() == "1" ) {
                jQuery.datepicker._getInst( event.target ).dpDiv.css( "width", "300px" );
            } else {
                jQuery.datepicker._getInst( event.target ).dpDiv.css( "width", "40em" );
            }
        }
        });
        var avd = 0;
        var chd = 0;
        var dateToday = new Date();
        dateToday.setDate(dateToday.getDate() + 7); 
        jQuery( "#e_deliverydate" ).val("").datepicker( { dateFormat: "d MM, yy", minDate: dateToday,beforeShowDay: jQuery.datepicker.noWeekends,
            onClose:function( dateStr, inst ) {
                if ( dateStr != "" ) {
                    var monthValue = inst.selectedMonth+1;
                    var dayValue = inst.selectedDay;
                    var yearValue = inst.selectedYear;
                    var all = dayValue + "-" + monthValue + "-" + yearValue;
                    jQuery( "#h_deliverydate" ).val( all );
                }
            }            
        }).focus( function ( event ) {
            jQuery.datepicker.afterShow( event );
        });jQuery( "#e_deliverydate" ).parent().append( "<br><small style=font-size:10px;>We will try our best to deliver your order on the specified date.</small>" );} );
</script>
<div class="page_header_wrap mmoInnerHeaderm clearfix">

    <div class="ak-container">

        <header class="entry-header">

            <?php the_title('<h2 class="entry-title">', '</h2>'); ?>

        </header><!-- .entry-header -->

        <?php accesspress_breadcrumbs() ?>

    </div>
</div>

<div class="inner">

    <main id="main" class="site-main clearfix">

        <div id="primary" class="content-area woocommerce">

            <form action="http://example.in/edit-delivery-address/?ordership=<?php echo $order_ID;?>" name="extra_shipping" method="post">

            <h3>Delivery Address</h3>
            <p id="_shipping_first_name_field" class="form-row form-row form-row-first">
                <label class="" for="_shipping_first_name">First Name</label>
                <input type="text" value="<?php echo $shipping_firs;?>" placeholder="" id="_shipping_first_name" name="shipping_first_name" class="input-text ">
            </p>              
            <p id="_shipping_last_name_field" class="form-row form-row form-row-last">
                <label class="" for="_shipping_last_name">Last Name</label>
                <input type="text" value="<?php echo $shipping_last;?>" placeholder="" id="_shipping_last_name" name="shipping_last_name" class="input-text ">
            </p>
            <div class="clear"></div>  
            <p id="shipping_email_field" class="form-row form-row ">
                <label class="" for="shipping_email">Email Address</label>
                <input type="text" value="<?php echo $shipping_email;?>" placeholder="" id="shipping_email" name="shipping_email" class="input-text ">
            </p>             
            <p id="s2id_shipping_country" class="form-row form-row form-row-wide address-field update_totals_on_change select2-container country_to_state country_select validate-required">
                <label class="" for="_shipping_country">Country <abbr title="required" class="required">*</abbr></label>
                <select class="country_to_state country_select " id="_shipping_country" name="shipping_country" tabindex="-1" title="Country *">
                    <option value="">Select a country…</option>
                    <?php 
                    $countrylist = array("AU" => "Australia","CA" => "Canada","FR" => "France","DE" => "Germany","IN" => "India","IT" => "Italy","GB" => "United Kingdom (UK)","US" => "United States (US)","NZ" => "New Zealand");
                    foreach ($countrylist as $key => $value) {
                        ?>
                        <option value="<?php echo $key;?>" <?php if($key==$shipping_coun){?>selected = "selected"<?php } ?>><?php echo $value;?></option>
                        <?php
                    }
            ?>        
            </select>
            </p>
            <p id="shipping_address_1_field" class="form-row form-row validate-required">
                <label class="" for="shipping_address_1">Address <abbr title="required" class="required">*</abbr></label>
                <input type="text" value="<?php echo $shipping_addr1;?>" placeholder="Street address" id="shipping_address_1" name="shipping_address_1" class="input-text ">
            </p>
            <p id="shipping_address_2_field" class="form-row form-row">
                <input type="text" value="<?php echo $shipping_addr2;?>" placeholder="Apartment, suite, unit etc. (optional)" id="shipping_address_2" name="shipping_address_2" class="input-text ">
            </p>         
            <!-- <p id="shipping_phone_field" class="form-row form-row ">
                <label class="" for="shipping_phone">Phone</label>
                <input type="text" value="<?php //echo $$shipping_phone;?>" placeholder="" id="shipping_phone" name="shipping_phone" class="input-text ">
            </p> -->                
            <p id="_shipping_postcode_field" class="form-row form-row address-field validate-postcode">
                <label class="" for="_shipping_postcode">ZIP</label>
                <input type="text" value="<?php echo $shipping_post;?>" placeholder="" id="_shipping_postcode" name="shipping_postcode" class="input-text ">
            </p><div class="clear"></div>                
            <p class="form-row form-row " id="e_deliverydate_field">
                <label for="e_deliverydate" class="">Delivery Date&nbsp;</label>
                <input  style="width: 300px;"  type="text" class="input-text" name="delivery_date" id="e_deliverydate"  value="<?php echo $ddate;?>" />
            </p>
            <div class="clear"></div> 
           <p class="form-row form-row">
            <select style="width: 300px;" name="shipping_accomodation" id="shipping_accomodation" class="select " data-placeholder="">
                <option value="">Type of accommodation</option>
                <option value="University accommodation" <?php if($accomodation=='University accommodation'){?>selected='selected'<?php } ?>>University accommodation</option>
                <option value="Private dorm accommodation" <?php if($accomodation=='Private dorm accommodation'){?>selected='selected'<?php } ?>>Private dorm accommodation</option>
                <option value="Private flat" <?php if($accomodation=='Private flat'){?>selected='selected'<?php } ?>>Private flat</option>
            </select>
            </p>
             <div class="clear"></div> 
            <p class="form-row form-row">
                <input type="submit" value="Save Address" name="save_address_temp" class="button">
            </p>

        </form>


        </div>

    </main>

</div>

现在,当用户填写所有字段并单击“保存”时,页面会保存所有数据,但只需刷新并重定向到同一页面。

我想保存所有数据,另外还想将用户重定向到我的帐户页面。有没有办法一次点击保存按钮来实现这两个目标?

0 个答案:

没有答案