• Resolved youngtuan

    (@youngtuan)


    Is it possible to add “the profit” to the packing slip? Its for our own use. So for each order you can see the profit.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hi @youngtuan,

    Are you buy any chance using some type of plugin that records your net gain or are you just using WooCommerce (WC)?

    Thread Starter youngtuan

    (@youngtuan)

    Just using woocommerce

    Plugin Contributor Yordan Soares

    (@yordansoares)

    I wonder how do you get the profit amount from every order. If not with a plugin, how do you know how much is it? If it’s with a perceptual calculation, you could get the total amount and work with it to calculate the profit.

    Let’s say that you calculate the 20% of the total from every order as your profit, so you can use this code snippet to display that amount in your order data:

    /**
     * Calculate profit based on perceptual amount
     */
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_delivery_date', 10, 2 );
    function wpo_wcpdf_delivery_date ($template_type, $order) {
    	if ($template_type == 'invoice') {
    		$total_amount = $order->get_total();
    		$profit_rate = 20; // Change this with your actual profit percentage
    		$profit_amount = wc_price( $total_amount * $profit_rate / 100 );
    		?>
    		<tr class="profit-amount">
    			<th>Profit:</th>
    			<td><?php echo $profit_amount; ?></td>
    		</tr>
    		<?php
    	}
    }

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Profit calculation’ is closed to new replies.