Orders, Payments, Shipping

9

questions

How do you add refunds to a gateway?

Add refunds to $this->supports and implement process_refund( $order_id, $amount, $reason ) calling the provider's API.

How do you add your own WooCommerce email?

A class extends WC_Email with trigger() and templates, registered through woocommerce_email_classes. Then the email has its settings in WooCommerce → Settings → Emails.

How does processing differ from completed?

processing — payment received, the order has to be packed and shipped. completed — fulfilled. For virtual and downloadable products WooCommerce sets completed right after payment.

What does payment_complete() do?

It sets the status (processing or completed), saves the transaction ID and the payment date, reduces stock if it wasn't reduced yet and fires the woocommerce_payment_complete hook.

What does process_payment() return?

An array with result (success or failure) and redirect — the URL to send the customer to: the provider's page or the thank-you page.

What is a shipping package?

An array with the cart items, the shipping address and the total, for which the methods calculate rates. The cart can be split into several packages with woocommerce_cart_shipping_packages.

Where do you plug in "after payment" logic?

woocommerce_payment_complete or woocommerce_order_status_processing, not the thank-you page. Heavy actions go through Action Scheduler.

Why is the shipping price "stuck"?

Rates are cached in the session by the package hash. If only the method settings changed, the cart takes the old cache. Clear the shipping cache in tests.

Why must a webhook be idempotent?

Providers retry delivery if they didn't get a 200 in time, and they may send several events about one payment. Processing it again must not change the result.