Magento: How to create different content for multiple stores
single,single-post,postid-16371,single-format-standard,,-,ajax_fade,page_not_loaded,qode-theme-ver-5.9,wpb-js-composer js-comp-ver-4.3.4,vc_responsive

Magento: How to create different content for multiple stores


24 Jul Magento: How to create different content for multiple stores

Magento: How to create different content for multiple stores

For anyone who is running multiple stores on one install, I’m sure you’ve come to realise it can be slightly complex to specify custom functions or content for different stores. I was recently presented with the issue, so I thought I’d share the method I used to get Magento to do what I wanted.

So, what is this code used for you ask? Well, as an example; you may want to show specific content for domestic customers, and show different content for international customers. By default, Magento doesn’t offer such an intricate solution ‘out of the box’ as far as I’m aware.. Pages, yes. But content blocks, no. Someone correct me if I’m wrong.

Before we begin, I’m going to assume you already have an understanding of how to configure and set up multiple Magento stores. If you don’t, here is a guide to get you started. If you do, or already have multiple store views setup, awesome.. Keep reading.



Step 1
First and foremost, we need to gather the store view codes for the stores we want to have a specific function or content. These are found under Store View Name in Configuration -> Manage Stores. You’ll need to click on the link of the Store View Name to get the code itself. For this example, I’m going to use StoreTwo as a store code.

Step 2
Now that you have your store view codes written down, we can begin with the coding side of things. We will be using simple PHP if/else statements to achieve what we want. I have set out two examples below, one for if you want to display content from a Static CMS block, and the other if you want to include custom code and/or functions.

What does it do? The code below uses a core Magento function to collect the Store Code. Then with our custom PHP code, we’re checking if a specific store view code exists (in this case StoreTwo) and if it does, then display specific content for the second store view. Otherwise, display content for the main store view. It’s quite simple really.

Where do I put the code? This part is really up to you. You can put the snipplets anywhere you want, but they will only work in .phtml files

To include store specific CMS Static Blocks

To include store specific bits of PHP code

For installs that have 3 or more Store Views

If you are using more than two store views, you will need to include an additional elseif statement in your loop, see below for an example.


Jenny Tran
No Comments

Post A Comment