以编程方式将Woocommerce商店页面作为主页 [英] Woocommerce shop page as a main page programmatically

查看:165
本文介绍了以编程方式将Woocommerce商店页面作为主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在eshop(woocommerce)上工作,我需要将shop页面定义为主页面,但只能使用一种语言.

I'm working on eshop (woocommerce) and I need to define the shop page as a main page but only for one language.

例如,如果myshop.com被捷克共和国的某人浏览,我想将商店页面定义为主页.如果有人来自德国,他会看到一个正常的主页.

For instance if myshop.com is browse by someone from Czech Republic, I want to define the shop page as an homepage. If someone is from Germany he see a normal homepage.

原因:

我不能仅仅重定向捷克客户,因为之后他们看不到主页.

I can't just redirect Czech customers, because they couldn't see homepage after.

而且我无法保存会话或进行类似的操作,因为我希望他们始终将购物页面作为主页来查看,而不仅仅是一次.

And I can't save session or make something like this because I want them to see the shop page all the time as an home page, not only once.

推荐答案

这里是个主意:

  • 当用户来自捷克语并且访问首页时,将其设置为3000万,然后将其重定向到商店页面.
  • 在商店页面上,捷克用户可以在Cookie有效期之前转到首页.

代码:

在function.php文件中

// function for shortening language ID
function wplang() {
    $lang = get_bloginfo('language').'';
    $lang = explode("-", $lang);
    return $lang[0];
}

在header.php文件中(在开头).您必须设置正确的网址...

In header.php file (at the beginning). You have to set the correct url…

<?php     
    // Only for Czech users
    if ( wplang() == 'cz' )
    {
        czcookie = $_COOKIE['wpczech'];

        // if a valid cookie isn't set to 'cz' value
        if ( czcookie != 'cz' )
        {
            // Set a cookie for 30 mn with 'cz' value
            setcookie('wpczech', 'cz', time()+1800, null, null , false , true);
            
            // redirecting to shop page
            header('Location: url_of_your_cz_shop_page');
        }
    }
?>

必须对代码进行修改和测试……

The code has to be adapted and tested…

这篇关于以编程方式将Woocommerce商店页面作为主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆