| 1 |
<?php |
| 2 |
/** |
| 3 |
** Give Notice |
| 4 |
**/ |
| 5 |
function forumax_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><?php esc_html_e('Upgrade to Forumax Pro', 'forumax'); ?></strong></p> |
| 22 |
<p><?php esc_html_e('Massive discount', 'forumax'); ?></p> |
| 23 |
</div> |
| 24 |
</div> |
| 25 |
<div class="bbpc-col"> |
| 26 |
<img src="<?php echo esc_url( FORUMAX_IMG . 'icon/coupon.svg' ); ?>" |
| 27 |
alt="<?php echo esc_attr_x( 'Coupon', 'coupon', 'forumax' ); ?>" class="coupon-icon"> |
| 28 |
<div class="bbpc-col-text"> |
| 29 |
<p><strong><?php esc_html_e('Up to 40% Off', 'forumax'); ?></strong></p> |
| 30 |
<p><?php esc_html_e('This is limited time offer!', 'forumax'); ?></p> |
| 31 |
</div> |
| 32 |
</div> |
| 33 |
<div class="bbpc-col"> |
| 34 |
<img src="<?php echo esc_url( FORUMAX_IMG . 'icon/cursor-hand.svg' ); ?>" |
| 35 |
alt="<?php echo esc_attr_x( 'Coupon', 'coupon', 'forumax' ); ?>" class="coupon-icon"> |
| 36 |
<div class="bbpc-col-text"> |
| 37 |
<p><strong><?php esc_html_e('Grab the deal', 'forumax'); ?></strong></p> |
| 38 |
<p><?php esc_html_e('Before it expires!', 'forumax'); ?></p> |
| 39 |
</div> |
| 40 |
</div> |
| 41 |
<div class="bbpc-col"> |
| 42 |
<div class="bbpc-col-box"> |
| 43 |
<label for="coupon"><?php esc_html_e('Coupon Code:', 'forumax'); ?></label> |
| 44 |
<div class="coupon-container"> |
| 45 |
<input type="text" value="DASH40" id="coupon" class="coupon" readonly> |
| 46 |
<span class="copy-message"><?php esc_html_e('Coupon copied.', 'forumax'); ?></span> |
| 47 |
<button class="copy-btn"><?php esc_html_e('Copy', 'forumax'); ?></button> |
| 48 |
</div> |
| 49 |
</div> |
| 50 |
</div> |
| 51 |
<div class="bbpc-col"> |
| 52 |
<a href="https://forumax.spider-themes.net/pricing/" class="buy-btn" target="_blank"><?php esc_html_e('Claim Discount', 'forumax'); ?></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 esc_url_raw( 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 esc_js( 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 |
}); |
| 97 |
</script> |
| 98 |
<?php |
| 99 |
} |
| 100 |
|
| 101 |
add_action( 'wp_ajax_bbpc_dismiss_offer_notice', 'forumax_dismiss_offer_notice' ); |
| 102 |
|
| 103 |
function forumax_dismiss_offer_notice() { |
| 104 |
check_ajax_referer( 'bbpc-dismiss-notice', 'nonce' ); |
| 105 |
|
| 106 |
if ( is_user_logged_in() ) { |
| 107 |
$user_id = get_current_user_id(); |
| 108 |
update_user_meta( $user_id, 'bbpc_offer_dismissed', '1' ); |
| 109 |
|
| 110 |
wp_send_json_success( array( 'message' => esc_html__('Notice dismissed for this user.', 'forumax') ) ); |
| 111 |
} else { |
| 112 |
wp_send_json_error( array( 'message' => esc_html__('User not logged in.', 'forumax') ) ); |
| 113 |
} |
| 114 |
|
| 115 |
wp_die(); |
| 116 |
} |
| 117 |
|