WooCommerce: Automating Hourly Support Package Renewals Using Saved Cards

In a Business Bloomer Club Slack thread, members explored an innovative solution to automate support hour top-ups for clients who pre-purchase hourly support packages.

Rather than relying on a traditional subscription, they needed an approach that allows for on-demand billing as soon as additional hours are required. With stored credit card information available in WooCommerce via Stripe or PayPal, there are ways to create a seamless “auto-purchase” experience, allowing customers to receive a pending order and complete payments without manual checkout.

Here’s how to leverage saved card data in WooCommerce for streamlined renewals and hassle-free billing.

Step 1: Understanding Saved Cards in WooCommerce

WooCommerce offers the ability to save card details for future purchases when using Stripe and PayPal. With a billing agreement in place, this feature is particularly useful for businesses that rely on recurring payments for services.

In this case, saved cards allow the merchant to create a pending order for extra support hours and prompt an automated payment on behalf of the client, without requiring them to initiate the payment manually.

Step 2: Creating Pending Orders for Extra Support Hours

To automate the process, you can set up WooCommerce to generate a new order automatically when a client reaches the end of their prepaid hours. Here’s a snippet for creating a pending order programmatically:

function create_support_package_order($customer_id, $hours) {
    $order = wc_create_order();
    $user = get_user_by('ID', $customer_id);

    // Adding the support package to the order
    $product_id = 123; // replace with the ID for your support package
    $order->add_product(wc_get_product($product_id), 1, array(
        'name' => 'Additional ' . $hours . ' Hours Support Package',
        'subtotal' => 100 * $hours, // replace with your pricing logic
    ));

    $order->set_customer_id($customer_id);
    $order->calculate_totals();
    $order->update_status('pending');

    return $order->get_id();
}

Using this approach, an order for additional hours is created in “pending” status. You can then trigger payment either via WooCommerce’s “Order Pay” page or by charging the stored card automatically.

Step 3: Automate Payments with Saved Cards

If the client agrees to automatic renewals, you can use WooCommerce’s “pay for order” link or directly charge the saved card. WooCommerce Stripe allows you to charge a saved card programmatically:

$order_id = create_support_package_order($customer_id, 5); // 5 hours
$order = wc_get_order($order_id);
$stripe_customer_id = get_user_meta($customer_id, '_stripe_customer_id', true);
if ($stripe_customer_id) {
    // Process payment
    $charge = WC_Stripe_API::request(array(
        'amount' => $order->get_total() * 100,
        'currency' => $order->get_currency(),
        'customer' => $stripe_customer_id,
        'description' => 'Auto-renewal for support hours',
    ));
    if ($charge->status == 'succeeded') {
        $order->payment_complete($charge->id);
    }
}

This method will charge the customer’s saved card directly, bypassing the checkout page. It’s a highly efficient approach, although make sure that security and authorization protocols, like 2FA, are considered if enabled.

Conclusion

Automating top-up payments for support hours in WooCommerce offers flexibility and convenience to clients who regularly require on-demand service.

By leveraging WooCommerce’s saved payment methods, you can seamlessly handle additional purchases without forcing clients through a repetitive checkout flow. Whether opting for automatic or manual payment triggers, WooCommerce provides versatile tools that make it easy to tailor purchases to the specific needs of your business model.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *