Customizing WooCommerce Deposits for a Tailored Experience

Recently, a client reached out for some help with their workflow when processing balance payments for deposit orders on their site. They take a deposit for custom tailored garments and then invoice the remaining balance after confirming measurements and when they’re ready to craft the piece for their customer. Because of this, they often have additional charges or items that they want to add to the balance invoice before sending it to the customer. By default, the WooCommerce Deposits plugin sends an email when the “Invoice Remaining Balance” button is clicked and the subsequent order is set to Pending Deposit Payment status which is not editable.

Prevent WooCommerce Deposits from Automatically Emailing Invoices for Balance Payments

To give more control over when balance payment invoices are sent, you can disable this functionality using a custom filter. This ensures that the “Invoice Remaining Balance” button creates the order without automatically sending an email to the customer.

add_filter('woocommerce_deposits_should_send_invoice_remaining_balance_email', 'sprucely_disable_invoice_remaining_balance_email', 10, 2);
/**
 * Disable the invoice remaining balance email for balance payment orders.
 *
 * @param bool $send_email Whether to send the email.
 * @param int  $new_order_id The new order ID.
 *
 * @return bool $send_email Whether to send the email.
 */
function sprucely_disable_invoice_remaining_balance_email($send_email, $new_order_id) {
    return false;
}

How It Works

The woocommerce_deposits_should_send_invoice_remaining_balance_email filter allows us to control whether an email should be sent when the remaining balance is invoiced. By returning false, we stop the automatic email, giving you the flexibility to review or modify the balance payment order before sending it manually.

This adjustment is particularly useful for businesses that need to add custom charges or adjustments before notifying customers about their balance payment. It ensures that the information is accurate and up-to-date, which can help reduce errors and improve the overall customer experience.

Be sure to remember to “Send order details to customer” from the Order actions dropdown once you’re ready to send the invoice to the customer.

Make “Pending Deposit Payment” Status WooCommerce Orders Editable

By default, WooCommerce Deposits doesn’t allow editing of orders with certain statuses, including the “Pending Deposit Payment” status. This limitation can be inconvenient, especially if you need to make adjustments to an order before the balance payment is finalized and sent.

To solve this, we implemented a simple filter that allows orders with the pending-deposit status to be editable:

add_filter( 'wc_order_is_editable', 'sprucely_make_pending_deposit_editable', 10, 2 );
/**
 * Make pending deposit orders editable.
 *
 * @param bool $is_editable Whether the order is editable.
 * @param WC_Order $order The order object.
 *
 * @return bool $is_editable Whether the order is editable.
 */
function sprucely_make_pending_deposit_editable( $is_editable, $order ) {
	if ( $order->has_status( 'pending-deposit' ) ) {
		$is_editable = true;
	}
	return $is_editable;
}

Customize the “(excludes tax)” Text in Order Emails

In addition to controlling email notifications, our client wanted to provide more clarity in the order emails by modifying the default “(excludes tax)” text in the “Future Payments” row. They needed this text to also mention any custom add-ons or adjustments that might apply to the remaining balance.

Here’s how we customized the text:

add_filter( 'gettext', 'modify_future_payments_tax_text_translatable', 10, 3 );
/**
 * Modify the translatable text for future payments tax message.
 *
 * @param string $translated_text Translated text.
 * @param string $text Text to translate.
 * @param string $domain Text domain.
 *
 * @return string $translated_text Translated text to be included in the plugin.
 */
function modify_future_payments_tax_text_translatable( $translated_text, $text, $domain ) {
	// Check if the text matches the one you want to change
	if ( $domain === 'woocommerce-deposits' && $text === '(excludes tax)' ) {
		// Replace the text
		$translated_text = '(excludes tax and any custom add-ons or adjustments)';
	}

	return $translated_text;
}

Making the Text More Informative

This modification uses the gettext filter, which allows you to change any translatable text within WordPress and its plugins. By identifying the specific text and domain, we replaced “(excludes tax)” with “(excludes tax and any custom add-ons or adjustments).” This small change helps ensure that customers are fully informed about what their future payments may include.

Customizing Order Item Names for Scheduled Deposits

In some cases, if a customer has multiple deposits open, it’s helpful to clearly label balance payment orders so that they’re easy to track back to the original order for the customer. We’ve added a feature that automatically updates the item names in these orders to include the original order number, making it immediately clear which order the payment is associated with.

// Add custom order item name for scheduled orders.
add_action( 'woocommerce_deposits_create_order', 'sprucely_custom_update_deposit_order_item_name', 10, 1 );

/**
 * Update order item name for deposit orders.
 *
 * @param int $new_order_id The new order ID.
 */
function sprucely_custom_update_deposit_order_item_name( $new_order_id ) {
	$new_order = wc_get_order( $new_order_id );

	if ( 'wc_deposits' === $new_order->get_created_via() ) {
		// Get the parent order ID.
		$original_order_id = $new_order->get_parent_id();
		if ( ! empty( $original_order_id ) ) {
			// Get the original order.
			$original_order = wc_get_order( $original_order_id );

			// Get the sequential order number.
			$sequential_order_number = $original_order->get_meta( '_order_number' );

			// Loop through each item in the new order.
			foreach ( $new_order->get_items() as $item_id => $item ) {
				// Update the item name.
				$new_item_name = sprintf(
					'Balance for Order #%1$s - %2$s',
					$sequential_order_number,
					$item->get_name()
				);

				// Set the new item name.
				wc_update_order_item( $item_id, array( 'order_item_name' => $new_item_name ) );
			}
		}
	}
}

This function automatically updates the name of each item in a newly created balance payment order. It adds a prefix like “Balance for Order #12345” to the item name, where #12345 is the original order number.

This change helps in two ways:

  1. Clear Association: It makes it easy to see at a glance which original order a balance payment is for, reducing the chance of confusion, especially when managing multiple payments.
  2. Improved Tracking: By adding the original order number to the item names, tracking and managing these payments becomes more straightforward, particularly in reports or when reviewing order details.

Requires Sequential Order Numbering: This version is only compatible with stores running Sequential Order Numbers for WooCommerce. So if you do not use this plugin, there will be some small tweaks needed before you implement this in your store.

Buttoning it All Up

With these customizations bundled into one plugin, you can now efficiently customize deposit orders, prevent confusing emails to customers, and ensure that order items are clearly labeled for better order management. This plugin is available on our GitHub repository, and we welcome contributions or suggestions.

If you need help with customizing your WooCommerce store, feel free to schedule a Free Initial Consultation to meet and discuss your needs.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top