Skip to content Skip to sidebar Skip to footer

Woocommerce Shop Page As A Main Page Programmatically

I'm working on eshop (woocommerce) and I need to define the shop page as a main page but only for one language. For instance if myshop.com is browse by someone from Czech Republic,

Solution 1:

Here is the idea:

  • When user is from Czech and come to the home page a coockie is set for 30 mn before it's redirected to the shop page.
  • Once on the shop page the Czech user can go to the home page before the cookie expiration time.

The code:

In function.php file

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

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

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

        // if a valid cookie isn't set to 'cz' valueif ( 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…

Post a Comment for "Woocommerce Shop Page As A Main Page Programmatically"