Question

I'm using the WordPress Shopp plugin to sell products on my WordPress site. So far I love this plugin but I'm trying to do something custom and unfortunately I'm not good enough with PHP to figure this out on my own (I've done tons of research too!).

Here is what I am trying to accomplish...

To display the product title for each individual product Shopp uses the following code to reference the product title...

<?php shopp('product','name'); ?>

What I am trying to do is reference the product name and if for example the product name says something like 'FLIR H-Series Thermal Imaging Camera' I want my code to detect whether or not the product title contains the word 'FLIR' in it and if it DOES contain the word 'FLIR' I want it to echo a FLIR logo image (let's say the URL of the image is http://example.com/images/flir.jpg). Alternatively I would want it to echo a Thermal-Eye logo image anytime the word 'Thermal-Eye' is found in the product title, etc. How could I go about modifying the code to do this?

Hopefully this make sense, thanks for any help!

Was it helpful?

Solution

<?php
$keywords = array('FLIR', 'Thermal-Eye');
foreach($keywords as $word)
{
    if(preg_match('/'.$word.'/i', shopp('product','name', 'return=true')))
        echo $word;
}
?>

UPDATE: If you want to echo out a unique image based on the word, rather than the word itself, you can do something like:

if(preg_match('/'.$word.'/i', shopp('product','name', 'return=true')))
        echo '<img src="'.get_bloginfo('stylesheet_directory').'/images/'.$word.'.jpg" />';

So in the case of FLIR, you just need to make sure FLIR.jpg exists within the images folder in your theme directory.

Best thing to do is to play around with it and see what works for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top