Coupon image instead of store image


  • Tiago
    Newbie 0 points
    March 23, 2019 at 5:13 pm

    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?

  • Chris
    Chris
    Newbie 36 points
    April 2, 2019 at 2:44 pm

    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.

  • JamesD
    JamesD
    Super Guru 1,702 points
    April 25, 2019 at 2:06 am

    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]');
        }
    }

  • Richard
    Newbie 19 points
    December 15, 2019 at 11:25 pm

    didn’t work pls help

  • JamesD
    JamesD
    Super Guru 1,702 points
    December 16, 2019 at 3:57 am

    Clip/copy method no longer works with the post.

    I’ve attached a file with the code to place in your _functions.php file. You can copy/paste from the file. A text file with the code will be extracted when unzipped.

    Attachments:
    You must be logged in to view attached files.

  • Richard
    Newbie 19 points
    December 16, 2019 at 4:24 am

    Thanks so much James! but it’s still not working. All the codes just showed on top of the home page like before. I pasted the codes into /wp-content/themes/CP9/_coupon/template/_functions.php. is that the right place to paste it? Thanks again!

  • JamesD
    JamesD
    Super Guru 1,702 points
    December 16, 2019 at 4:35 am

    @Richard
    Was the _functions.php file totally empty?
    If so, add <?php as the very first line then add ?> to the very last line. The code should be placed in between those two tags.


  • Richard
    Newbie 19 points
    December 16, 2019 at 4:59 am

    Thanks again! Adding <?php ?> did make the codes go away on top of the page but the page keeper is still there, nothing has changed yet.


  • Richard
    Newbie 19 points
    December 16, 2019 at 5:01 am

    Or is it possible to simply remove those store images next the the coupons? Thank you!

  • JamesD
    JamesD
    Super Guru 1,702 points
    December 16, 2019 at 8:02 am

    Hmmm… there has been some changes to the theme settings since this code was originally posted.

    “…but the page keeper is still there”

    Sorry, not following. Are you referring to an image placeholder?

    To clarify, are you referring to the problem being on the listing page only or on multiple pages?
    Do you have a URL(s) where the problem can be seen?

    “Or is it possible to simply remove those store images next the the coupons?”

    Are you referring to removing the image section in the sidebar above the store name?
    If not, could you clarify a little more and/or provide an image the end result look you’re going for?

Viewing 10 posts - 1 through 10 (of 10 total)

New Business Themes for WordPress 2020

Start your new website today!

View Business Themes