使用 WPML 插件为所有语言更改 "return to shop" URL
Changing "return to shop" URL for all languages with WPML plugin
在我的 WooCommerce 网上商店中,我想将“Return 更改为商店” URL 为自定义 URL。我尝试在我的活动主题的 function.php
文件中使用下面的代码,但它不起作用。
在我的网站上,我有五种由 WPML 商业插件管理的活动语言。它还运行一个脚本,确保来自这些国家的访问者被重定向到他们自己的语言。
/**
* 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' );
我怎样才能让它工作以获取当前的语言商店 link?
谢谢。
Update2: 在你的代码中,你需要使用:
- WooCommerce
wc_get_page_id()
获取 WooCommerce 商店页面 ID 的函数。
- WPML
wpml_object_id
过滤挂钩以获取商店的当前语言翻译页面 ID。
- WooCommerce
wc_get_page_permalink()
that is used by the filter hook itself (see HERE)
通过 material,您可以获得商店的当前翻译 link(或任何其他 link)。
因此您的代码将是:
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 文件或任何插件文件。
最后我测试了,它有效…
在我的 WooCommerce 网上商店中,我想将“Return 更改为商店” URL 为自定义 URL。我尝试在我的活动主题的 function.php
文件中使用下面的代码,但它不起作用。
在我的网站上,我有五种由 WPML 商业插件管理的活动语言。它还运行一个脚本,确保来自这些国家的访问者被重定向到他们自己的语言。
/**
* 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' );
我怎样才能让它工作以获取当前的语言商店 link?
谢谢。
Update2: 在你的代码中,你需要使用:
- WooCommerce
wc_get_page_id()
获取 WooCommerce 商店页面 ID 的函数。 - WPML
wpml_object_id
过滤挂钩以获取商店的当前语言翻译页面 ID。 - WooCommerce
wc_get_page_permalink()
that is used by the filter hook itself (see HERE)
通过 material,您可以获得商店的当前翻译 link(或任何其他 link)。
因此您的代码将是:
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 文件或任何插件文件。
最后我测试了,它有效…