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. By default, FooSales doesn’t store any data obtained from Square other than the Square order ID that is generated upon successfully processing a payment. You can have FooSales store the Square processing fees as a hidden meta value for WooCommerce orders captured via FooSales where Square was used as the payment method.
Add the following code snippet to your theme’s functions.php file which will check to see if an order has a Square order ID when marked as completed. Next, it will use the Square API to retrieve the Square order from your account, add up all the payment fees involved for that order and save it as a meta field for the WooCommerce order.
add_action('woocommerce_order_status_completed', function($order_id) { $square_order_id = get_post_meta($order_id, "_foosales_square_order_id", true); if ( !empty($square_order_id) ) { //FooSales config $config = new FooSales_Config(); //API helper methods require_once($config->helper_path.'foosales-api-helper.php'); $order_result = fsfwc_get_square_order($square_order_id); // Uses the Square API to retrieve the order $square_fees = 0.0; if ( $order_result['status'] === 'success' ) { $order = $order_result['order']; if ( !empty($order['tenders']) ) { foreach ( $order['tenders'] as $tender ) { $square_fees += ((float)($tender['processing_fee_money']['amount']) / 100.0); // The fee is returned as cents, so divide it by 100.0 } } } update_post_meta($order_id, "_foosales_square_fee_amount", $square_fees); } });
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>'; } }