This is a Developer-level document. If you are unfamiliar with code/templates and resolving potential conflicts, please engage with a developer who is familiar with FooSales and/or WooCommerce. These snippets are provided as a courtesy and are intended as a starting point to assist any specific customization needs. We are unable to provide support for customizations under our Terms of Service.
Capture Square Fees When Completing an Order #
If you’re using a third-party export plugin to export your orders and you’re processing payments with Square, you might want to include the fees that Square deducts from the payment in your sales export. This help document previously contained a code snippet that captured Square processing fees as meta data upon order completion. This, however, didn’t support split payments and since the structure of plugin 1.40.0+ has been completely overhauled, the code snippet will no longer function. The functionality contained within the code snippet has been added to the plugin’s core functionality which also supports split payments and various order submit statuses in plugin version 1.40.2
Please note that if you previously added the code snippet to your functions.php file, you must remove it to prevent critical errors when submitting orders through FooSales.
You can read more about how Square fees are captured in our Square Payment Integration help document.
Add the order note from FooSales to the WooCommerce admin emails #
Add the following code snippet to your theme’s functions.php file if you want the “Order note” that you added to the order in FooSales to display in the WooCommerce admin emails.
add_action( 'woocommerce_email_order_meta', 'woo_add_order_notes_to_email', 10, 4 );
function woo_add_order_notes_to_email($order, $sent_to_admin, $plain_text, $email) {
if ( isset($post->ID) )
$id = $post->ID;
else
$id = $order->ID;
if ($sent_to_admin && 'foosales_app' === get_post_meta($id, '_foosales_order_source', true)) {
$args = array(
'order_id' => $id,
'type' => ''
);
$notes = wc_get_order_notes( $args );
echo '<h2>' . __( 'Order Notes', 'woocommerce' ) . '</h2>';
echo '<ul class="order_notes">';
if ( $notes ) {
?>
<li>
<div class="note_content">
<?php echo wpautop( wptexturize( wp_kses_post( $notes[count($notes)-1]->content ) ) ); ?>
</div>
</li>
<?php
} else {
echo '<li>' . __( 'There are no notes for this order yet.', 'woocommerce' ) . '</li>';
}
echo '</ul>';
}
}
Send Order Details from FooSales, and Completed email from website #
Add the following code snippet to your theme’s functions.php file if you want to automatically send the Order Details email when an order is placed through FooSales, and send the Completed email when an order is placed through your website’s front-end.
add_filter( 'woocommerce_email_enabled_customer_completed_order', 'is_foosales', 9999, 2 );
function is_foosales($enabled, $order ) {
if ( ! empty( $order ) && 'foosales_app' === $order->get_meta( '_foosales_order_source', true ) ) {
return false;
}
return $enabled;
}
add_action( 'woocommerce_order_status_completed', 'send_invoice_on_completed' );
function send_invoice_on_completed( $order_id ) {
$wc_order = wc_get_order($order_id);
if ( ! empty( $wc_order ) && 'foosales_app' === $wc_order->get_meta( '_foosales_order_source', true ) ) {
$emails = WC()->mailer()->get_emails();
$emails['WC_Email_Customer_Invoice']->trigger( $order_id );
}
}
Implement partial use for coupon codes #
Add the following code snippet to your theme’s functions.php file if you want to enable the partial use of coupon codes. This means that if the coupon code amount is more than the total price of the items being purchased, then the amount owed would be 0 and the total price will be deducted from the coupon code amount so that there is credit left to be used in the future.
// 1. Process coupon adjustments on active order completion/processing
add_action( 'woocommerce_order_status_processing', 'adjust_partially_used_coupon_amount', 10, 1 );
add_action( 'woocommerce_order_status_completed', 'adjust_partially_used_coupon_amount', 10, 1 );
function adjust_partially_used_coupon_amount( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order ) {
return;
}
// Prevent code from running multiple times on the same order
if ( $order->get_meta( '_coupon_amount_adjusted' ) ) {
return;
}
$coupons = $order->get_coupons();
foreach ( $coupons as $item ) {
$code = $item->get_code();
$coupon = new WC_Coupon( $code );
// Only target fixed cart discount coupons
if ( $coupon->get_id() && $coupon->is_type( 'fixed_cart' ) ) {
$coupon_original_amount = (float) $coupon->get_amount();
$discount_used = (float) $item->get_discount();
if ( $coupon_original_amount > $discount_used ) {
// PARTIAL USE: Reduce balance and restore 1 usage count so it stays active
$remaining_balance = $coupon_original_amount - $discount_used;
$coupon->set_amount( $remaining_balance );
$usage_count = $coupon->get_usage_count();
if ( $usage_count > 0 ) {
$coupon->set_usage_count( $usage_count - 1 );
}
$coupon->save();
} elseif ( $coupon_original_amount > 0 && abs( $coupon_original_amount - $discount_used ) < 0.001 ) {
// FINAL USE: Full remaining balance spent. Set balance to 0.
// Leave usage_count alone so WooCommerce natural limits apply.
$coupon->set_amount( 0 );
$coupon->save();
}
}
}
// Mark order as processed so status changes don't re-trigger this logic
$order->update_meta_data( '_coupon_amount_adjusted', 'yes' );
$order->save();
}
// 2. Restore coupon balance if order is cancelled, refunded, or failed
add_action( 'woocommerce_order_status_cancelled', 'restore_partially_used_coupon_amount', 10, 1 );
add_action( 'woocommerce_order_status_refunded', 'restore_partially_used_coupon_amount', 10, 1 );
add_action( 'woocommerce_order_status_failed', 'restore_partially_used_coupon_amount', 10, 1 );
function restore_partially_used_coupon_amount( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order ) {
return;
}
// Only attempt restoration if the coupon was previously deducted on this order
if ( ! $order->get_meta( '_coupon_amount_adjusted' ) ) {
return;
}
// Prevent double-restoration if status changes between cancelled/refunded
if ( $order->get_meta( '_coupon_amount_restored' ) ) {
return;
}
$coupons = $order->get_coupons();
foreach ( $coupons as $item ) {
$code = $item->get_code();
$coupon = new WC_Coupon( $code );
if ( $coupon->get_id() && $coupon->is_type( 'fixed_cart' ) ) {
$current_balance = (float) $coupon->get_amount();
$discount_applied = (float) $item->get_discount();
if ( $discount_applied > 0 ) {
$restored_balance = $current_balance + $discount_applied;
$coupon->set_amount( $restored_balance );
// If coupon was completely depleted (0) and is now restored, reduce usage count so it reactivates
if ( $current_balance == 0 && $restored_balance > 0 ) {
$usage_count = $coupon->get_usage_count();
if ( $usage_count > 0 ) {
$coupon->set_usage_count( $usage_count - 1 );
}
}
$coupon->save();
}
}
}
// Mark order meta as restored
$order->update_meta_data( '_coupon_amount_restored', 'yes' );
$order->save();
}
Hide WooCommerce Point of Sale Settings #
Add the following code snippet to your theme’s functions.php file if you want to hide the Point of Sale settings added by WooCommerce as of version 11.
// Remove the built-in WooCommerce Point of Sale settings tab.
add_filter( 'woocommerce_settings_tabs_array', 'remove_wc_pos_settings_tab', 999, 1 );
function remove_wc_pos_settings_tab( $tabs ) {
if ( isset( $tabs['point-of-sale'] ) ) {
unset( $tabs['point-of-sale'] );
}
return $tabs;
}
// Remove the All Sales Channels filter on the Orders page.
add_action( 'admin_head', 'hide_sales_channel_order_filter' );
function hide_sales_channel_order_filter() {
$screen = get_current_screen();
// Target the WooCommerce orders listing screen
if ( isset( $screen->id ) && ( $screen->id === 'woocommerce_page_wc-orders' || $screen->id === 'edit-shop_order' ) ) {
echo '<style>
select[name="_created_via"],
#sales_channel {
display: none !important;
}
</style>';
}
}
