第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

WooCommerce - 登錄后重定向到上一頁(yè)

WooCommerce - 登錄后重定向到上一頁(yè)

PHP
哈士奇WWW 2021-07-07 18:57:28
我一直在尋找可以處理數(shù)小時(shí)的插件和片段,但沒(méi)有成功。每個(gè)答案都不適用于我。我在菜單中有“登錄”鏈接,通向 WooCommerce 的“我的帳戶”頁(yè)面,其中顯示了登錄表單。我希望客戶在成功登錄后返回到點(diǎn)擊“登錄”鏈接的頁(yè)面。wp_get_referer()$_SERVER["HTTP_REFERER"]如果放在掛鉤的函數(shù)中,則不返回任何內(nèi)容并返回我的帳戶頁(yè)面woocommerce_login_redirect(我使用 PHP 調(diào)試控制臺(tái)進(jìn)行檢查)。這是我的代碼:// Redirect user after login.add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 );function wc_custom_user_redirect( $redirect, $user ) {    // Get the first of all the roles assigned to the user    $role = $user->roles[0];    $dashboard = admin_url();           if (in_array($role, array('administrator', 'shop_manager', 'editor', 'author', 'contributor'))) {        $redirect = $dashboard;             } elseif (in_array($role, array('customer', 'subscriber'))) {        $redirect = $_SERVER["HTTP_REFERER"];              } else {        $redirect = $_SERVER["HTTP_REFERER"];           }    return $redirect;}這是我使用的過(guò)濾器出現(xiàn)在 WooCommerce 代碼中的位置:/**    * Process the login form.    */   public static function process_login() {       $nonce_value = isset( $_POST['_wpnonce'] ) ? $_POST['_wpnonce'] : '';       $nonce_value = isset( $_POST['woocommerce-login-nonce'] ) ? $_POST['woocommerce-login-nonce'] : $nonce_value;       if ( ! empty( $_POST['login'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-login' ) ) {           try {               $creds = array(                   'user_password' => $_POST['password'],                    'remember' => isset( $_POST['rememberme'] ),   ); 
查看完整描述

3 回答

?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊

請(qǐng)嘗試以下代碼,希望對(duì)您有所幫助。將以下代碼粘貼到當(dāng)前活動(dòng)的主題functions.php文件中。


// start global session for saving the referer url

function start_session() {

    if(!session_id()) {

        session_start();

    }

}

add_action('init', 'start_session', 1);


// get  referer url and save it 

function redirect_url() {

    if (! is_user_logged_in()) {

        $_SESSION['referer_url'] = wp_get_referer();

    } else {

        session_destroy();

    }

}

add_action( 'template_redirect', 'redirect_url' );


//login redirect 

function login_redirect() {

    if (isset($_SESSION['referer_url'])) {

        wp_redirect($_SESSION['referer_url']);

    } else {

        wp_redirect(home_url());

    }

}

add_filter('woocommerce_login_redirect', 'login_redirect', 1100, 2);


查看完整回答
反對(duì) 回復(fù) 2021-07-09
?
守著星空守著你

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊

這將解決您的問(wèn)題



add_filter( 'woocommerce_login_redirect', function(){

   

       wp_safe_redirect(wp_get_referer());


}, 10, 2 );


查看完整回答
反對(duì) 回復(fù) 2021-07-09
?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

我們必須使用 WordPress 引薦來(lái)源功能:

例如,通過(guò)單擊添加到購(gòu)物車(chē)按鈕或任何按鈕來(lái)存儲(chǔ)以前的 URL,在會(huì)話或隱藏字段中設(shè)置引用 URL。登錄或注冊(cè)成功后,將 WooCommerce 成功登錄重定向添加到該 URL。


查看完整回答
反對(duì) 回復(fù) 2021-07-09
  • 3 回答
  • 0 關(guān)注
  • 242 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)