From 8d4ddcca05b85508101c72b3651b886bc2fe6033 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 12 Dec 2016 13:36:51 -0500 Subject: [PATCH] Adding coupon ribbon on the member list. Both grib and list view with the Coupon Ribbon. Color and font size can be overridden in theme. --- css/front.css | 28 ++++++++++++++++++++++++++++ setup/frontHooks.php | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/css/front.css b/css/front.css index a0f1263..b2a7bfc 100644 --- a/css/front.css +++ b/css/front.css @@ -86,3 +86,31 @@ margin-left: 0 !important;; } } +.ribbon { + position:absolute; + z-index: 2; + padding:0; + margin:0; + text-align:center; + white-space:nowrap; + overflow:hidden; + transform-origin:0 100%; + box-shadow:0 1px 6px 0 rgba(0,0,0,.12),0 1px 6px 0 rgba(0,0,0,.12); + background-color:#ffeb3b; + color:rgba(0,0,0,0.9); + height:30px; + width:200px; + top:-30px; + transform:rotateZ(45deg); + padding-left:30px; + padding-right:30px; + line-height:30px; + right:-58.57864376269px; + -webkit-transform:rotateZ(45deg); + -moz-transform:rotateZ(45deg); + -o-transform:rotateZ(45deg); +} +.ribbon:hover { + cursor: pointer; + color:rgba(0,0,0,0.9); +} diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 60e8099..81d4aba 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -25,13 +25,51 @@ * * *** Also note that parameters will be in the context of the main front controller constructor. *** */ +function glmMemberHasActiveCoupon( $memberId ) { + global $wpdb, $config; + $id = filter_var( $memberId, FILTER_VALIDATE_INT ); + if ( !$id ) { + return false; + } + $sql = " + SELECT count(id) + FROM " . GLM_MEMBERS_COUPONS_PLUGIN_DB_PREFIX . "coupons + WHERE current_date BETWEEN start_date AND end_date AND status = 10 + AND ref_dest = %d"; + return $wpdb->get_var( $wpdb->prepare( $sql, $memberId ) ); +} // Add content to member detail page - Get it from the existing coupon shortcode add_filter('glm-member-db-front-members-detail-descriptionAfter', - function($content, $id) { + function( $content, $id ) { global $config; if ( $config['settings']['detail_show_coupons'] ) { - $eventData = do_shortcode('[glm-members-coupons-list member='.$id.' template="member-detail"]'); - $content .= $eventData; + $coupon_count = glmMemberHasActiveCoupon( $id ); + if ( $coupon_count ) { + $eventData = do_shortcode('[glm-members-coupons-list member='.$id.' template="member-detail"]'); + $content .= $eventData; + } + } + return $content; + }, + 10, + 2 +); +add_filter('glm-member-db-front-members-list-memberTop', + function ( $content, $id ) { + global $wpdb, $config; + $memberId = filter_var( $id, FILTER_VALIDATE_INT); + if ( $memberId && $config['settings']['detail_show_coupons'] ) { + $coupon_count = glmMemberHasActiveCoupon( $id ); + if ( $coupon_count ) { + // Get the member slug so we can build the member detail url + $sql = " + SELECT member_slug + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX. "members + WHERE id = %d"; + $memberSlug = $wpdb->get_var( $wpdb->prepare( $sql, $memberId ) ); + $url = get_bloginfo('url') . '/member-detail/' . $memberSlug . '/?expanded=coupons'; + $content = 'Savings Coupon'; + } } return $content; }, -- 2.17.1