/* function process_bacs_subscription_payments() { $today = date(‘Y-m-d’); $max_runs = 25; // ✅ Set a limit to prevent infinite loops $run_count = 0; while ($run_count < $max_runs) { // Get the next subscription that is due today $args = array( 'post_type'…Continue reading
function add_store_credit_on_subscription_renewal($order_id) { $logger = wc_get_logger(); $order = wc_get_order($order_id); if (!$order) { $logger->error(“⚠️ Store Credit Error: Order {$order_id} not found on first attempt.”, array( ‘source’ => ‘store-credit-renewal’ )); sleep(2); // Wait 2 seconds and try again $order = wc_get_order($order_id); if…Continue reading
add_action(‘woocommerce_cart_calculate_fees’, ‘apply_branch_discount_by_category’, 20, 1); function apply_branch_discount_by_category($cart) { if (is_admin() && !defined(‘DOING_AJAX’)) return; // Ensure it only runs on the front-end $user = wp_get_current_user(); // Only apply discount for users with the “branch” role if (!in_array(‘branch’, (array) $user->roles)) { return; }…Continue reading
add_filter(‘woocommerce_package_rates’, ‘force_free_shipping_for_branch_users’, 20, 2); function force_free_shipping_for_branch_users($rates, $package) { $user = wp_get_current_user(); // Only apply for users with the “branch” role if (!empty($user->roles) && in_array(‘branch’, (array) $user->roles)) { // Create a free shipping method $free_shipping_rate = new WC_Shipping_Rate( ‘free_shipping_branch’, // Rate…Continue reading
function display_store_credit_debug_info() { $test_user_id = 11; if (!is_checkout()) return; if (get_current_user_id() != $test_user_id) return; // Only show for the test user $user_id = get_current_user_id(); $store_credit_balance = get_user_meta($user_id, ‘acfw_store_credit_balance’, true); $session_store_credit = WC()->session->get(‘acfw_store_credit_amount’); $cart_total = WC()->cart->total; echo ‘ ‘; echo ‘🛠…Continue reading
function set_default_shipping_method() { if (is_admin() || !is_checkout()) { return; } $packages = WC()->shipping->get_packages(); foreach ($packages as $key => $package) { if (!empty($package[‘rates’])) { $shipping_methods = array_keys($package[‘rates’]); $chosen_method = WC()->session->get(‘chosen_shipping_methods’); if (empty($chosen_method)) { WC()->session->set(‘chosen_shipping_methods’, array($shipping_methods[0])); } } } } add_action(‘woocommerce_before_cart’, ‘set_default_shipping_method’);…Continue reading
add_filter( ‘woocommerce_order_email_verification_required’, ‘__return_false’ );Continue reading
function add_custom_order_action($actions) { $actions[‘notify_backorder_available’] = __(‘Notify Backorder Ready’, ‘woocommerce’); return $actions; } add_filter(‘woocommerce_order_actions’, ‘add_custom_order_action’); function process_custom_order_action($order) { $order_id = $order->get_id(); $customer_email = $order->get_billing_email(); $customer_name = $order->get_billing_first_name(); // Email subject and message $subject = “Your Backordered Book is Ready for Collection!”;…Continue reading
if (function_exists(‘acf_add_options_page’)) { acf_add_options_page([ ‘page_title’ => ‘Supplier Settings’, ‘menu_title’ => ‘Suppliers’, ‘menu_slug’ => ‘supplier-settings’, ‘capability’ => ‘manage_options’, ‘redirect’ => false ]); }Continue reading
add_action(‘admin_init’, function () { // Only run for admins on the dashboard if (!current_user_can(‘manage_options’)) return; // Check if we’ve already imported if (get_option(‘supplier_list_imported’)) return; $supplier_data = [ ‘127659’ => ‘1804 Books’, ‘127660’ => ‘Abebooks.com’, ‘127661’ => ‘Africa Book Centre’, ‘127662’…Continue reading