| 1 |
<?php |
| 2 |
/** |
| 3 |
** Give Notice |
| 4 |
**/ |
| 5 |
function bbpc_offer_notice() { |
| 6 |
if ( is_user_logged_in() ) { |
| 7 |
$user_id = get_current_user_id(); |
| 8 |
$dismissed = get_user_meta( $user_id, 'bbpc_offer_dismissed', true ); |
| 9 |
|
| 10 |
if ( '1' === $dismissed ) { |
| 11 |
return; // Don't show the notice if it has been dismissed by this user |
| 12 |
} |
| 13 |
} |
| 14 |
?> |
| 15 |
<div class="bbpc-offer-wrap"> |
| 16 |
<div class="bbpc-offer"> |
| 17 |
<button class="dismiss-btn">×</button> |
| 18 |
<div class="bbpc-col"> |
| 19 |
<span class="dashicons dashicons-megaphone"></span> |
| 20 |
<div class="bbpc-col-text"> |
| 21 |
<p><strong> Upgrade to Bbp Core Pro </strong></p> |
| 22 |
<p> Massive discount </p> |
| 23 |
</div> |
| 24 |
</div> |
| 25 |
<div class="bbpc-col"> |
| 26 |
<img src="<?php echo BBPC_IMG ?>/icon/coupon.svg" |
| 27 |
alt="<?php echo esc_attr_x( 'Coupon', 'coupon', 'bbp-core' ); ?>" class="coupon-icon"> |
| 28 |
<div class="bbpc-col-text"> |
| 29 |
<p><strong> Up to 40% Off </strong></p> |
| 30 |
<p> This is limited time offer! </p> |
| 31 |
</div> |
| 32 |
</div> |
| 33 |
<div class="bbpc-col"> |
| 34 |
<img src="<?php echo BBPC_IMG ?>/icon/cursor-hand.svg" |
| 35 |
alt="<?php echo esc_attr_x( 'Coupon', 'coupon', 'bbp-core' ); ?>" class="coupon-icon"> |
| 36 |
<div class="bbpc-col-text"> |
| 37 |
<p><strong> Grab the deal </strong></p> |
| 38 |
<p> Before it expires! </p> |
| 39 |
</div> |
| 40 |
</div> |
| 41 |
<div class="bbpc-col"> |
| 42 |
<div class="bbpc-col-box"> |
| 43 |
<label for="coupon">Coupon Code:</label> |
| 44 |
<div class="coupon-container"> |
| 45 |
<input type="text" value="DASH40" id="coupon" class="coupon" readonly> |
| 46 |
<span class="copy-message">Coupon copied.</span> |
| 47 |
<button class="copy-btn">Copy</button> |
| 48 |
</div> |
| 49 |
</div> |
| 50 |
</div> |
| 51 |
<div class="bbpc-col"> |
| 52 |
<a href="https://spider-themes.net/bbp-core/pricing/" class="buy-btn" target="_blank"> Claim Discount </a> |
| 53 |
</div> |
| 54 |
</div> |
| 55 |
</div> |
| 56 |
|
| 57 |
<script> |
| 58 |
document.addEventListener('DOMContentLoaded', function () { |
| 59 |
const copyBtn = document.querySelector('.copy-btn'); |
| 60 |
const couponInput = document.querySelector('.coupon'); |
| 61 |
const copyMessage = document.querySelector('.copy-message'); |
| 62 |
const dismissBtn = document.querySelector('.dismiss-btn'); |
| 63 |
const offerWrap = document.querySelector('.bbpc-offer-wrap'); |
| 64 |
|
| 65 |
copyBtn.addEventListener('click', function () { |
| 66 |
navigator.clipboard.writeText(couponInput.value).then(() => { |
| 67 |
copyMessage.style.display = 'inline'; |
| 68 |
setTimeout(() => { |
| 69 |
copyMessage.style.display = 'none'; |
| 70 |
}, 1000); |
| 71 |
}).catch(err => { |
| 72 |
console.error('Could not copy text: ', err); |
| 73 |
}); |
| 74 |
}); |
| 75 |
|
| 76 |
dismissBtn.addEventListener('click', function () { |
| 77 |
offerWrap.style.display = 'none'; |
| 78 |
|
| 79 |
// Make an AJAX request to save the dismissal for the logged-in user |
| 80 |
fetch('<?php echo admin_url( 'admin-ajax.php' ); ?>', { |
| 81 |
method: 'POST', |
| 82 |
credentials: 'same-origin', |
| 83 |
headers: { |
| 84 |
'Content-Type': 'application/x-www-form-urlencoded' |
| 85 |
}, |
| 86 |
body: 'action=bbpc_dismiss_offer_notice&nonce=<?php echo wp_create_nonce( "bbpc-dismiss-notice" ); ?>' |
| 87 |
}).then(response => response.json()).then(data => { |
| 88 |
if (!data.success) { |
| 89 |
console.error('Error dismissing the notice:', data.message); |
| 90 |
} |
| 91 |
}).catch(err => { |
| 92 |
console.error('Error dismissing the offer:', err); |
| 93 |
}); |
| 94 |
}); |
| 95 |
}); |
| 96 |
</script> |
| 97 |
<?php |
| 98 |
} |
| 99 |
|
| 100 |
add_action( 'wp_ajax_bbpc_dismiss_offer_notice', 'bbpc_dismiss_offer_notice' ); |
| 101 |
|
| 102 |
function bbpc_dismiss_offer_notice() { |
| 103 |
check_ajax_referer( 'bbpc-dismiss-notice', 'nonce' ); |
| 104 |
|
| 105 |
if ( is_user_logged_in() ) { |
| 106 |
$user_id = get_current_user_id(); |
| 107 |
update_user_meta( $user_id, 'bbpc_offer_dismissed', '1' ); |
| 108 |
|
| 109 |
wp_send_json_success( array( 'message' => 'Notice dismissed for this user.' ) ); |
| 110 |
} else { |
| 111 |
wp_send_json_error( array( 'message' => 'User not logged in.' ) ); |
| 112 |
} |
| 113 |
|
| 114 |
wp_die(); |
| 115 |
} |
| 116 |
|