Update concat authors for all products

function update_concatenated_authors_for_all_products() { // Get all products $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, // Get all products ‘post_status’ => ‘publish’, ); $products = get_posts($args); foreach ($products as $product) { // Reuse the function to update the concatenated…Continue reading

Add discount for non zero store credit

add_action(‘woocommerce_cart_calculate_fees’, ‘apply_subscriber_discount’, 10, 1); function apply_subscriber_discount($cart) { if (is_admin() && !defined(‘DOING_AJAX’)) return; // Ensure it only runs on the front-end $user = wp_get_current_user(); // Apply 10% discount only if the user has the role ‘subscriber’ if (in_array(‘subscriber’, (array) $user->roles)) {…Continue reading

Automatically Add Store Credit on BACS Subscription Renewal

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

Discounts for Branch users FE

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

Free shipping for Branch

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

Display debug at checkout for test user

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

Set default shipping method at checkout

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

Backorder ready for collection notification

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