';
});
/**
* Re
// TEMP: reset opcache
add_action('wp_ajax_ats_reset_opcache', function() {
if (function_exists('opcache_reset')) { opcache_reset(); echo 'reset'; } else { echo 'no opcache'; }
die();
});
commended way to include parent theme styles.
* Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme
*/
add_action('wp_enqueue_scripts', 'theme_enqueue_styles', 998);
function theme_enqueue_styles() {
wp_enqueue_style('flozen-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('flozen-child-style', get_stylesheet_uri());
}
/**
* Your code goes below
*/
function wc_get_product_id_by_variation_sku($sku) {
$args = array(
'post_type' => 'product_variation',
'meta_query' => array(
array(
'key' => '_sku',
'value' => $sku,
)
)
);
// Get the posts for the sku
$posts = get_posts( $args);
if ($posts) {
return $posts[0];
} else {
return false;
}
}
function wc_minimum_cart_value() {
// Set the minimum cart value
$minimum = 10;
if ( WC()->cart->total < $minimum ) {
// Display error message on the cart page
if( is_cart() ) {
wc_print_notice(
sprintf( 'Your current cart total is %s — you must have an order with a minimum of %s to place your order.' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
} else {
// Display error message on the checkout page
wc_add_notice(
sprintf( 'Your current cart total is %s — you must have an order with a minimum of %s to place your order.' ,
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
}
}
}
// Hook to enforce the minimum cart value during the checkout process
add_action( 'woocommerce_checkout_process', 'wc_minimum_cart_value' );
// Hook to enforce the minimum cart value before displaying the cart
add_action( 'woocommerce_before_cart' , 'wc_minimum_cart_value' );
// Hook to enforce the minimum cart value on the checkout page
add_action( 'woocommerce_before_checkout_form', 'wc_minimum_cart_value', 20 );
function disable_cart_and_checkout_buttons() {
// Set the minimum cart value
$minimum = 10;
if ( WC()->cart->total < $minimum ) {
?>
id, ['edit-product', 'edit-page', 'edit-post'])) {
echo '';
}
});
// ===== WHOLESALE PAGE STYLES =====
add_action('wp_head', function() {
if (is_page('wholesale')) {
echo '';
}
});
// ===== DARK GOLD THEME — PHASE 2 =====
add_action('wp_head', function() {
if (is_admin()) return;
echo '';
}, 999);
// ============================================================
// PHASE 3 — Homepage Additional Sections
// ============================================================
add_filter('the_content', function($content) {
if (!is_front_page() && !is_home()) return $content;
$sections = '
';
return $content . $sections;
}, 20);
// === ATS MEMBERSHIP POPUP STEP ===
add_action('wp_footer', function() {
if (is_admin()) return;
?>
'ids'));
if (is_wp_error($cat_ids) || empty($cat_ids)) return false;
// Parent IDs: 163 = Tattoo Machines, 587 = Tattoo Transfer Paper & Printer
$parent_ids = array(163, 587);
$mp_ids = $parent_ids;
foreach ($parent_ids as $pid) {
$children = get_term_children($pid, 'product_cat');
if (!is_wp_error($children)) $mp_ids = array_merge($mp_ids, $children);
}
// Extra brand-specific machine subcategories not directly under 163
$extra = array(580, 400, 609, 601, 602, 597, 443, 596, 412);
$mp_ids = array_merge($mp_ids, $extra);
return !empty(array_intersect($cat_ids, $mp_ids));
}
// 2. On order complete: assign premium_member role if product 19333 purchased
add_action('woocommerce_order_status_completed', function($order_id) {
$order = wc_get_order($order_id);
if (!$order) return;
$user_id = $order->get_user_id();
if (!$user_id) return;
foreach ($order->get_items() as $item) {
if ((int)$item->get_product_id() === 19333) {
$user = new WP_User($user_id);
$user->add_role('premium_member');
$now = time();
update_user_meta($user_id, 'ats_premium_since', $now);
update_user_meta($user_id, 'ats_premium_expires', strtotime('+1 year', $now));
update_user_meta($user_id, 'ats_premium_year_spend', 0);
break;
}
}
}, 10);
// 3. On order complete: track cumulative spend within membership year
add_action('woocommerce_order_status_completed', function($order_id) {
$order = wc_get_order($order_id);
if (!$order) return;
$user_id = $order->get_user_id();
if (!$user_id) return;
$user = new WP_User($user_id);
if (!in_array('premium_member', (array)$user->roles)) return;
$expires = (int)get_user_meta($user_id, 'ats_premium_expires', true);
if (!$expires || time() > $expires) return;
// Skip if this order is the membership purchase itself
foreach ($order->get_items() as $item) {
if ((int)$item->get_product_id() === 19333) return;
}
$current = (float)get_user_meta($user_id, 'ats_premium_year_spend', true);
// Use subtotal (pre-discount) so spend tracks actual product value
$order_subtotal = 0;
foreach ($order->get_items() as $item) {
$order_subtotal += (float)$item->get_subtotal();
}
update_user_meta($user_id, 'ats_premium_year_spend', $current + $order_subtotal);
}, 15);
// 4. Apply cart discount for premium members
add_action('woocommerce_cart_calculate_fees', function($cart) {
if (is_admin() && !defined('DOING_AJAX')) return;
$user_id = get_current_user_id();
if (!$user_id) return;
$user = new WP_User($user_id);
if (!in_array('premium_member', (array)$user->roles)) return;
$expires = (int)get_user_meta($user_id, 'ats_premium_expires', true);
if (!$expires || time() > $expires) return;
$discount = 0;
foreach ($cart->get_cart() as $item_key => $item) {
// Skip the membership product itself
if ((int)$item['product_id'] === 19333) continue;
$line_total = (float)$item['line_total'];
$rate = ats_is_machine_or_printer($item['product_id']) ? 0.05 : 0.10;
$discount += $line_total * $rate;
}
if ($discount > 0) {
$cart->add_fee(__('Premium Member Discount', 'flozen-theme-child'), -round($discount, 2));
}
});
// 5. On every page load: auto-renew or expire premium membership
add_action('init', function() {
if (!is_user_logged_in()) return;
$user_id = get_current_user_id();
$user = new WP_User($user_id);
if (!in_array('premium_member', (array)$user->roles)) return;
$expires = (int)get_user_meta($user_id, 'ats_premium_expires', true);
if (!$expires || time() <= $expires) return;
// Membership has expired — check if they qualify for free renewal
$year_spend = (float)get_user_meta($user_id, 'ats_premium_year_spend', true);
if ($year_spend >= 3000) {
// Free renewal: extend 1 year from expiry date, reset spend counter
update_user_meta($user_id, 'ats_premium_expires', strtotime('+1 year', $expires));
update_user_meta($user_id, 'ats_premium_year_spend', 0);
} else {
// Not eligible — remove premium role
$user->remove_role('premium_member');
}
});
// Register premium_member role (runs once on theme load)
add_action('after_switch_theme', function() {
if (!get_role('premium_member')) {
add_role('premium_member', 'Premium Member', array('read' => true));
}
});
// Also ensure role exists on every load (safe fallback)
add_action('init', function() {
if (!get_role('premium_member')) {
add_role('premium_member', 'Premium Member', array('read' => true));
}
}, 1);
// Shortcode: [ats_member_status] — shows membership status widget for logged-in premium members
add_shortcode('ats_member_status', function() {
if (!is_user_logged_in()) return '';
$user_id = get_current_user_id();
$user = new WP_User($user_id);
if (!in_array('premium_member', (array)$user->roles)) return '';
$expires = (int)get_user_meta($user_id, 'ats_premium_expires', true);
$spend = (float)get_user_meta($user_id, 'ats_premium_year_spend', true);
$target = 3000;
$pct = min(100, round(($spend / $target) * 100));
$days_left = max(0, ceil(($expires - time()) / 86400));
$renew_date = $expires ? date('d M Y', $expires) : '-';
ob_start(); ?>
★
PREMIUM MEMBER
Membership renews ( days left)
Free renewal progressS$ / S$3,000
% — = 100 ? 'You qualify for FREE renewal! 🎉' : 'Spend S$' . number_format($target - $spend, 2) . ' more for free renewal'; ?>
get_user_id();
if (!$user_id) return;
// Only for non-premium members
$user = new WP_User($user_id);
if (in_array('premium_member', (array)$user->roles)) return;
// Step 1: If this order used an earned discount, mark it as used
$discount_earned = (int)get_user_meta($user_id, 'ats_free_discount_earned', true);
if ($discount_earned) {
update_user_meta($user_id, 'ats_free_discount_earned', 0);
update_user_meta($user_id, 'ats_free_total_spend', 0);
}
// Step 2: Add this order's subtotal to cumulative spend
$order_subtotal = 0;
foreach ($order->get_items() as $item) {
$order_subtotal += (float)$item->get_subtotal();
}
$current_spend = (float)get_user_meta($user_id, 'ats_free_total_spend', true);
$new_spend = $current_spend + $order_subtotal;
// Step 3: Check if milestone reached
if ($new_spend >= 1000 && !get_user_meta($user_id, 'ats_free_discount_earned', true)) {
// Award 5% discount, carry over any excess spend
update_user_meta($user_id, 'ats_free_discount_earned', 1);
update_user_meta($user_id, 'ats_free_total_spend', $new_spend - 1000);
} else {
update_user_meta($user_id, 'ats_free_total_spend', $new_spend);
}
}, 20);
// Apply 5% discount at cart when reward is earned
add_action('woocommerce_cart_calculate_fees', function($cart) {
if (is_admin() && !defined('DOING_AJAX')) return;
$user_id = get_current_user_id();
if (!$user_id) return;
$user = new WP_User($user_id);
if (in_array('premium_member', (array)$user->roles)) return;
// Only apply if they have earned a discount
if (!(int)get_user_meta($user_id, 'ats_free_discount_earned', true)) return;
$discount = 0;
foreach ($cart->get_cart() as $item) {
$discount += (float)$item['line_total'] * 0.05;
}
if ($discount > 0) {
$cart->add_fee(__('Loyalty Reward — 5% Off', 'flozen-theme-child'), -round($discount, 2));
}
}, 10);
// Shortcode: [ats_free_member_status] — spend progress widget for standard members
add_shortcode('ats_free_member_status', function() {
if (!is_user_logged_in()) return '';
$user_id = get_current_user_id();
$user = new WP_User($user_id);
if (in_array('premium_member', (array)$user->roles)) return '';
$spend = (float)get_user_meta($user_id, 'ats_free_total_spend', true);
$earned = (int)get_user_meta($user_id, 'ats_free_discount_earned', true);
$pct = min(100, round(($spend / 1000) * 100));
$remaining = max(0, 1000 - $spend);
ob_start(); ?>
☆
STANDARD MEMBER
🎉 5% discount ready — applies automatically at checkout!
Spend S$ more to earn 5% off your next order
Progress to next rewardS$ / S$1,000
% — S$ to go
Reward unlocked! Shop now to use your 5% discount.
Upgrade to Premium Membership for instant 10% off everything — no spend required.
roles)) {
wp_redirect(wc_get_page_permalink('myaccount'));
exit;
}
}
// Add premium product to cart and go straight to checkout
WC()->cart->empty_cart();
WC()->cart->add_to_cart(19333);
wp_redirect(wc_get_checkout_url());
exit;
});
// Force account creation at checkout when Premium Membership is in cart
add_filter('woocommerce_checkout_registration_required', function($required) {
if (is_user_logged_in()) return $required;
foreach (WC()->cart->get_cart() as $item) {
if ((int)$item['product_id'] === 19333) return true;
}
return $required;
});
// 3. Show "Upgrade to Premium" banner on My Account dashboard for non-premium members
add_action('woocommerce_account_dashboard', function() {
$user_id = get_current_user_id();
$user = new WP_User($user_id);
if (in_array('premium_member', (array)$user->roles)) {
// Already premium — show status instead
$expires = (int)get_user_meta($user_id, 'ats_premium_expires', true);
$days = $expires ? max(0, ceil(($expires - time()) / 86400)) : 0;
echo '
';
echo '★';
echo '
PREMIUM MEMBER
';
echo '
Membership expires in ' . $days . ' days | View benefits
';
echo '
';
} else {
// Not premium — show upgrade prompt
echo '
';
echo '
';
echo '☆';
echo '
Upgrade to Premium Membership
';
echo '
10% off all orders | 5% off machines & printers | Free renewal at S$3,000 spend