Created
July 17, 2020 13:53
-
-
Save wpsoul/a816ae273966e04f2956e5a1e6cbaaea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////// | |
// Offer List | |
////////////////////////////////////////////////////////////////// | |
if( !function_exists('wpsm_afflist_shortcode') ) { | |
function wpsm_afflist_shortcode( $atts, $content = null ) { | |
if(!isset($atts['show'])) { | |
$atts['show'] = 10; | |
} | |
if(isset($atts['cat']) && $atts['cat']): | |
$args = array( | |
'post_type' => 'thirstylink', | |
'thirstylink-category' => $atts['cat'], | |
'posts_per_page' => $atts['show'], | |
); | |
elseif(isset($atts['ids']) && $atts['ids']): | |
$aff_ids = explode(',', $atts['ids']); | |
$args = array( | |
'post_type' => 'thirstylink', | |
'post__in' => $aff_ids, | |
'numberposts' => '-1', | |
'orderby' => 'post__in', | |
); | |
else : | |
$args = array( | |
'post_type' => 'thirstylink', | |
'posts_per_page' => $atts['show'], | |
); | |
endif; | |
$rehub_aff_posts = get_posts($args); | |
$html ='<div class="aff_offer_links m25">'; | |
foreach($rehub_aff_posts as $aff_post) { | |
$attachments = get_posts( array( | |
'post_type' => 'attachment', | |
'post_mime_type' => 'image', | |
'posts_per_page' => -1, | |
'post_parent' => $aff_post->ID, | |
)); | |
if (!empty($attachments)) {$aff_thumb_list = wp_get_attachment_url( $attachments[0]->ID );} else {$aff_thumb_list ='';} | |
$term_list = wp_get_post_terms($aff_post->ID, 'thirstylink-category', array("fields" => "names")); | |
$term_ids = wp_get_post_terms($aff_post->ID, 'thirstylink-category', array("fields" => "ids")); | |
if (!empty($term_ids)) {$term_brand = $term_ids[0]; $term_brand_image = get_option("taxonomy_term_$term_ids[0]");} else {$term_brand_image ='';} | |
$html .='<div class="rehub_feat_block table_view_block">'; | |
if (get_post_meta( $aff_post->ID, 'rehub_aff_sticky', true) == '1') : | |
$html .='<div class="vip_corner"><span class="vip_badge"><i class="fa fa-thumbs-o-up"></i></span></div>'; | |
endif; | |
$html .='<div class="block_with_coupon">'; | |
$html .='<div class="offer_thumb"><a href="'.get_post_permalink($aff_post).'">'; | |
$params = array( 'width' => 120, 'height' => 90 ); | |
if (!empty($aff_thumb_list) ) : | |
$html .='<img src="'.bfi_thumb( $aff_thumb_list, $params ).'" alt="'.$aff_post->post_title.'" />'; | |
elseif (!empty($term_brand_image['brand_image'])) : | |
$html .='<img src="'.bfi_thumb( $term_brand_image['brand_image'], $params ).'" alt="'.$aff_post->post_title.'" />'; | |
else : | |
$html .='<img src="'.get_template_directory_uri().'/images/default/noimage_100_70.png" alt="'.$aff_post->post_title.'" />'; | |
endif; | |
$html .='</a></div>'; | |
$html .='<div class="desc_col">'; | |
$html .='<div class="offer_title"><a href="'.get_post_permalink($aff_post).'">'.$aff_post->post_title.'</a></div>'; | |
$html .='<p>'.get_post_meta( $aff_post->ID, "rehub_aff_desc", true ).'</p>'; | |
$rehub_aff_review_related = get_post_meta( $aff_post->ID, "rehub_aff_rel", true ); | |
if ( !empty($rehub_aff_review_related)) : | |
$html .='<a href="'.$rehub_aff_review_related.'" target="_blank" class="color_link">'.__("Read review", "rehub_framework").'</a>'; | |
endif; | |
$html .='</div>'; | |
$product_price = get_post_meta( $aff_post->ID, 'rehub_aff_price', true ); | |
$offer_price_old = get_post_meta( $aff_post->ID, 'rehub_aff_price_old', true ); | |
if ( !empty($product_price) || !empty($term_list[0])) : | |
$html .='<div class="price_col">'; | |
if (!empty($product_price)) : | |
$html .='<p><span class="price_count"><ins>'.$product_price.'</ins>'; | |
if($offer_price_old !='') : | |
$html .=' <del>'.$offer_price_old.'</del>'; | |
endif ; | |
$html .='</span></p>'; | |
endif ; | |
$html .='<div class="aff_tag">'; | |
$params = array( 'width' => 120, 'height' => 90 ); | |
if (!empty($term_brand_image['brand_image'])) : | |
$html .='<img src="'.bfi_thumb( $term_brand_image['brand_image'], $params ).'" alt="'.$aff_post->post_title.'" />'; | |
elseif (!empty($term_list[0])) : | |
$html .=''.$term_list[0].''; | |
endif; | |
$html .='</div>'; | |
$html .='</div>'; | |
endif; | |
$html .='<div class="buttons_col"><div class="priced_block">'; | |
$offer_btn_text = get_post_meta( $aff_post->ID, 'rehub_aff_btn_text', true ); | |
$offer_coupon = get_post_meta( $aff_post->ID, 'rehub_aff_coupon', true ); | |
$offer_coupon_date = get_post_meta( $aff_post->ID, 'rehub_aff_coupon_date', true ); | |
$offer_coupon_mask = get_post_meta( $aff_post->ID, 'rehub_aff_coupon_mask', true ); | |
if(!empty($offer_coupon_date)) : | |
$timestamp1 = strtotime($offer_coupon_date); | |
$seconds = $timestamp1 - time(); | |
$days = floor($seconds / 86400); | |
$seconds %= 86400; | |
if ($days > 0) { | |
$coupon_text = $days.' '.__('days left', 'rehub_framework'); | |
$coupon_style = ''; | |
} | |
elseif ($days == 0){ | |
$coupon_text = __('Last day', 'rehub_framework'); | |
$coupon_style = ''; | |
} | |
else { | |
$coupon_text = __('Coupon is Expired', 'rehub_framework'); | |
$coupon_style = 'expired_coupon'; | |
} | |
endif; | |
$html .='<div><a class="btn_offer_block" href="'.get_post_permalink($aff_post).'" target="_blank" rel="nofollow">'; | |
if($offer_btn_text !='') : | |
$html .=''.$offer_btn_text.''; | |
elseif(rehub_option('rehub_btn_text') !='') : | |
$html .=''.rehub_option("rehub_btn_text").''; | |
else : | |
$html .=''.__("Buy this item", "rehub_framework").''; | |
endif ; | |
$html .='</a></div>'; | |
if(!empty($offer_coupon)) : | |
wp_enqueue_script('zeroclipboard'); | |
if ($offer_coupon_mask !='1') : | |
$html .='<div class="rehub_offer_coupon not_masked_coupon'; | |
if(!empty($offer_coupon_date)): | |
$html .=' '.$coupon_style.''; | |
endif; | |
$html .='" data-clipboard-text="'.$offer_coupon.'"><i class="fa fa-scissors fa-rotate-180"></i><span class="coupon_text">'.$offer_coupon.'</span></div>'; | |
else: | |
$html .='<div class="rehub_offer_coupon masked_coupon'; | |
if(!empty($offer_coupon_date)): | |
$html .=' '.$coupon_style.''; | |
endif; | |
$html .='" data-clipboard-text="'.$offer_coupon.'" data-codeid="'.$aff_post->ID.'" data-dest="'.get_post_permalink($aff_post).'">'; | |
if(rehub_option('rehub_mask_text') !='') : | |
$html .=''.rehub_option("rehub_mask_text").''; | |
else: | |
$html .=''.__("Reveal coupon", "rehub_framework").'<i class="fa fa-external-link-square"></i>'; | |
endif; | |
$html .='</div>'; | |
endif; | |
if(!empty($offer_coupon_date)): | |
$html .='<div class="time_offer">'.$coupon_text.'</div>'; | |
endif; | |
endif ; | |
$html .='</div></div>'; | |
$html .='</div></div>'; | |
} | |
$html .='</div>'; | |
return $html; | |
} | |
add_shortcode('wpsm_afflist', 'wpsm_afflist_shortcode'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment