2017-02-14 12 views
4

WooCommerce 웹샵에서 "Return to shop" URL을 사용자 정의 URL로 변경하고 싶습니다. 내 활성 테마의 파일 function.php에서 아래 코드를 사용하려했지만 작동하지 않습니다.WPML 플러그인을 사용하는 모든 언어의 "shop to return"URL 변경

내 웹 사이트에는 WPML 상업용 플러그인으로 관리되는 5 개의 활성 언어가 있습니다. 또한이 국가의 방문자가 자신의 언어로 리디렉션되도록하는 스크립트를 실행합니다.

/** 
* Changes Return to Shop button URL on Cart page. 
* 
*/ 

function wc_empty_cart_redirect_url() { 
     return 'http://pacsymposium.com/'; 
} 
add_filter('woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url'); 

어떻게하면 현재 언어 상점 링크를 얻을 수 있습니까?

감사합니다.

답변

4

갱신 2 :

  • WooCommerce에게 wc_get_page_id() 기능을 WooCommerce 가게 페이지 ID를 얻을 수 : 코드에서, 당신은 사용할 필요가있다.
  • WPML wpml_object_id 쇼핑 언어로 번역 된 현재 언어를 가져 오는 필터 후크. 필터 훅 자체에 의해 사용되는
  • WooCommerce wc_get_page_permalink()는 가게 (또는 다른 링크)의 현재 번역 링크를 얻을 수 있습니다, 그 재료로

을 (HERE 참조).

그래서 코드가 될 것입니다 :

add_filter('woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url'); 
function wc_empty_cart_redirect_url() { 

    // Getting the shop ID 
    $shop_id = wc_get_page_id('shop'); 

    // Getting the current language ID for the shop page 
    $current_lang_id = apply_filters('wpml_object_id', $shop_id, 'page', TRUE); 

    // Getting the post object for the ID 
    $post = get_post($current_lang_id); 

    // Getting the slug from this post object 
    $slug = $post->post_name; 

    // We re-use wc_get_page_permalink() function just like in this hook 
    $link = wc_get_page_permalink($slug); 

    return $link; 
} 

코드는 플러그인 파일도 function.php의 활성 자식 테마 (또는 테마)의 파일이나 간다.

마침내 테스트를 거쳤습니다 ...