Coupon image instead of store image

WordPress Business Themes Forums Responsive Themes Coupon Theme Coupon image instead of store image

Coupon image instead of store image

March 23, 2019
 Tiago

  • Tiago
    Newbie 0 points

    Well,

    I would need your help since I can’t figure how to do this.
    In the listing/search results, if I have a store image, it will show the store logo instead of the coupon image we set (default theme).

    It only shows the coupon image if there’s no store image set.

    I would like the other way: it only shows the store image if there’s no coupon image.

    Can someone help me please?

    March 23, 2019 at 5:13 pm
  • Chris
    Chris
    Newbie 34 points

    I asked the same thing direct to customer service 5 months ago and was told by Customer service Marie I “didn’t need to show coupon images” because the store logo works well enough. Obviously, wrong answer when a single store can offer everything from bikes to “personal massagers” and the codes may only work on a particular item. Coupon level images are required.

    Did you install or build a child theme? You say (default theme). That’s fine, I do too – but use a child theme generator plugin or DYI to make a child theme from the default theme. You will have to edit some templates that you want separate from the core framework otherwise every update will ruin your site.

    When you are working with a child theme I can drop the code info here for you to get those sweet coupon level images.

    April 2, 2019 at 2:44 pm
  • JamesD
    JamesD
    Super Guru 1,290 points

    This should help get people started. It’ll show the first attached image.
    It removes the current COUPONIMAGE shortcode and adds it back to use a slightly modified version of the original shortcode function.
    Add it to the _functions.php

    remove_shortcode('COUPONIMAGE', 'ppt_shortcode_couponimage');
    add_shortcode( 'COUPONIMAGE',  'custom_shortcode_couponimage' );
    function custom_shortcode_couponimage ( $atts = "", $content = null ) { global $userdata, $CORE, $wpdb, $post; $STRING = "";
        extract( shortcode_atts( array(  'screenshot' => 0, 'term_id' => '', 'link' => 1, 'pathonly' => 0, 'single' => 0 , 'class' => "img-fluid" ), $atts ) );
        if(is_numeric($term_id)){
            $t = get_term_by('term_id', $term_id, 'store');
            $terms = array();
            $terms[0] = $t;
        }elseif(!isset($post->ID) || get_post_meta($post->ID,"image_array",true) == ""){
            if(!is_numeric($term_id)){
                $terms = wp_get_post_terms( $post->ID,'store', array("fields" => "all") );
                if(isset($terms[0])){
                    $thisID = $terms[0]->term_id;
                }elseif(isset($GLOBALS['flag-taxonomy']) ){
                    $term = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
                    if(isset($term->term_id)){
                        $terms = array();
                        $terms[0] =  $term;
                    }
                }
            }else{
                $t = get_term_by('term_id', $term_id, 'store');
                $terms = array();
                $terms[0] = $t;
            }
        }elseif(isset($post->ID) && is_numeric($post->ID) ){
            $terms = wp_get_post_terms( $post->ID,'store', array("fields" => "all") );
            if(isset($terms[0])){
                $thisID = $terms[0]->term_id;
            }
    
        }
        if(isset($terms[0])){
            $couponimgs = get_attached_media( 'image' );
            $obj = array_shift($couponimgs);
            $merchant_logo = (isset($obj->guid) && !empty($obj->guid))?$obj->guid:'';
    
            if( $screenshot == 0 && strlen(_ppt('storeimage_'.$terms[0]->term_id)) > 1 ){
                $merchant_logo = (!empty($merchant_logo))?$merchant_logo:_ppt('storeimage_'.$terms[0]->term_id);
                $l = get_term_link($terms[0]->slug, 'store');
                $img = "slug."' class='img-fluid' />";
            }elseif($single = 1 && strlen(_ppt('category_website_'.$terms[0]->term_id)) > 1){
                $img = do_shortcode('[SCREENSHOT url="'.$GLOBALS['CORE_THEME']['category_website_'.$terms[0]->term_id].'" alt="'.$terms[0]->name.'"]');
            }elseif( $screenshot == 0 && strlen(_ppt('category_icon_'.$terms[0]->term_id)) > 1 ){
                $merchant_logo = (!empty($merchant_logo))?$merchant_logo:_ppt('category_icon_'.$terms[0]->term_id);
                $l = get_term_link($terms[0]->slug, 'store');
                $img = "slug."' class='img-fluid' />";
            }elseif(strlen(_ppt('category_website_'.$terms[0]->term_id)) > 1){
                $img = do_shortcode('[SCREENSHOT url="'.$GLOBALS['CORE_THEME']['category_website_'.$terms[0]->term_id].'" alt="'.$terms[0]->name.'"]');
            }
            if(isset($img) && strlen($img) > 1){
                if($pathonly){
                    preg_match( '@src="([^"]+)"@' , $img , $match );
                    if(isset($match[1]) && !empty($match[1]) && substr($match[1],0 , 4) == "http"){
                        return $match[1];
                    }
                    preg_match( "@src='([^']+)'@" , $img , $match );
                    if(isset($match[1]) && !empty($match[1]) && substr($match[1],0 , 4) == "http"){
                        return $match[1];
                    }
                }
                if($link == 1){
                    return $img;
                }else{
                    return  preg_replace('/<a.*?(<img.*?>)<\/a>/', '$1', $img);
                }
            }
        }
    
        if($pathonly){
            return do_shortcode('[IMAGE pathonly=1]');
        }
        if($link == 1){
            return do_shortcode('[IMAGE link=1]');
        }else{
            return do_shortcode('[IMAGE]');
        }
    }
    April 25, 2019 at 2:06 am
Viewing 3 posts - 1 through 3 (of 3 total)

Didn't find what you were after?

Chat with us now

or contact our support team