'wpaf-coupon-widget',
'description' => __( 'Add Coupons and Deals to your widget areas.', 'affcoupon' )
);
// Creating the widget.
parent::__construct( 'wpaf_coupons_deals_widget', 'AffCoupon Widget', $widget_details );
}
/**
* This function displays the widget controls in Widget Admin Screen.
*
* @since 1.0
*/
public function form( $instance ) {
$coupon_name = ( isset( $instance['coupon_name'] ) ? $instance['coupon_name'] : '' );
$category_name = ( isset( $instance['category_name'] ) ? $instance['category_name'] : '' );
do_action( 'wpaf_widget_help_info_display' );
do_action( 'wpaf_widget_help_info_display' );
?>
'wpaf_coupons',
'title' => $widget_coupon_name,
'posts_per_page' => 1,
'no_found_rows' => true,
'ignore_sticky_posts' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'orderby' => 'post_date ID',
'order' => 'ASC',
) );
$wpaf_coupon = ( $wpaf_title_query->have_posts() ) ? $wpaf_title_query->posts[0] : null;
/**
* Arguments to be used for a custom Query.
*
* @since 1.0
*/
$wpaf_arg = array(
'p' => isset( $wpaf_coupon->ID ) ? $wpaf_coupon->ID : 0,
'posts_per_page' => '1',
'post_type' => 'wpaf_coupons',
'post_status' => 'publish',
);
/**
* New custom query to get post and post data
* from the custom coupon post type.
*
* @since 1.0
*/
$wpaf_coupon = new WP_Query( $wpaf_arg );
// Hide expired coupon feature.
$today = gmdate( 'd-m-Y' );
$hide_expired_coupon = get_option( 'wpaf_hide-expired-coupon' );
while ( $wpaf_coupon->have_posts() ) {
$wpaf_coupon->the_post();
global $wpaf_coupon_id;
$template = new WPAF_Template_Loader();
$wpaf_coupon_id = get_the_ID();
// Hide expired coupon feature (default is Not to hide).
if ( ! empty( $hide_expired_coupon ) || $hide_expired_coupon == "on" ) {
$expire_date = get_post_meta( $wpaf_coupon_id, 'coupon_details_expire-date', true );
if ( ! empty( $expire_date ) ) {
if ( (string)(int)$expire_date != $expire_date ) {
$expire_date = strtotime( $expire_date );
}
if ( $expire_date < strtotime( $today ) ) {
continue;
}
}
}
$coupon_template = get_post_meta( $wpaf_coupon_id, 'coupon_details_coupon-template', true );
if ( $coupon_template == 'Template One' ) {
$template->get_template_part( 'widget-one' );
} elseif ( $coupon_template == 'Template Two' ) {
$template->get_template_part( 'widget-two' );
} elseif ( $coupon_template == 'Template Three' ) {
$template->get_template_part( 'widget-three' );
} elseif ( $coupon_template == 'Template Five' ) {
$template->get_template_part( 'widget-five' );
} elseif ( $coupon_template == 'Template Six' ) {
$template->get_template_part( 'widget-six' );
} else {
$template->get_template_part( 'widget-default' );
}
}
wp_reset_postdata();
}
}