【问题标题】:Changing "return to shop" URL for all languages with WPML plugin使用 WPML 插件更改所有语言的“返回商店”URL
【发布时间】:2017-02-17 04:26:30
【问题描述】:

在我的 WooCommerce 网上商店中,我想将“返回商店” 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' );

我怎样才能使它工作以获取当前的语言商店链接?

谢谢。

【问题讨论】:

    标签: php wordpress woocommerce multilingual wpml


    【解决方案1】:

    Update2:在你的代码中,你需要使用:

    使用该材料,您可以获得商店的当前翻译链接(或任何其他链接)。

    所以你的代码将是:

    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 文件或任何插件文件中。

    最后我测试了,它可以工作了……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      • 2019-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多