1

在 Woocommerce 中,当您完成订单时,我正在处理我的自定义感谢页面。一切都已完成,但我需要将英语订单重定向到英语感谢页面和主要语言到主要感谢页面。

我已将此代码添加到,functions.php但它仅重定向到设置的 url。如何为 2 种不同的语言设置 2 个不同的 url?

主要语言:斯洛伐克语
第二语言:英语
用于翻译的插件:Polylang

我的代码:

add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' );
function woo_custom_redirect_after_purchase() {
    global $wp;

    if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) )
    {
        wp_redirect( '/dakujeme-za-objednavku/' );
        exit;
    }
}

当我使用此代码时,它仅重定向到未设置为 en_US 的 url(当语言为英语时,/vi/cam-on 不感谢您

add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
function bbloomer_redirectcustom( $order_id ){

    $order = new WC_Order( $order_id );

    if( get_locale() == 'en_US'){
        $url = get_site_url().'/thank-you';        
    }else{
        $url = get_site_url().'/vi/cam-on';
    }
    if ( $order->status != 'failed' ) {
        wp_redirect($url);
        exit;
    }
}
4

0 回答 0