Coupon image instead of store image

WordPress Business Themes Forums Responsive Themes Coupon Theme Coupon image instead of store image Reply To: Coupon image instead of store image

Discontinued - The forum content is out of date. For theme support please use our support desk here.

WordPress Business Themes Forums Responsive Themes Coupon Theme Coupon image instead of store image Reply To: Coupon image instead of store image

  • JamesD
    JamesD
    Super Guru 1,345 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
  • Didn't find what you were after?

    Chat with us now

    or contact our support team