Plugin Directory

Changeset 2097821


Ignore:
Timestamp:
05/30/2019 10:21:09 AM (7 years ago)
Author:
lewisself
Message:

Release 1.0.0

Location:
cost-price-for-woocommerce/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • cost-price-for-woocommerce/trunk/cost-price-for-woocommerce.php

    r1938543 r2097821  
    33    /**
    44     * Plugin Name: Cost Price for WooCommerce
    5      * Description: This plugin lets the admin input the cost price for all products.
     5     * Description: This plugin lets the admin calculate the profits they're making on orders and specific products.
    66     * Author:      Lewis Self
    7      * Version:     1.0.0
     7     * Author URI:  https://www.lewisself.co.uk
     8     * Version:     1.1.0
    89     * License:     GPL2+
    910     * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
    1011     *
    1112     * WC requires at least: 3.0.0
    12      * WC tested up to: 3.4.4
     13     * WC tested up to: 3.6.4
    1314     */
    1415
     
    4748     * Calculates order profits
    4849     *
    49      * @param   WC_Order    $order  The order which to calculate the profits
     50     * @param       WC_Order    $order  The order which to calculate the profits
    5051     *
    5152     * @return  bool | int  The calculated profit. If not possible to calculate, return false
     
    6364            $single_cost_price = get_post_meta($product['product_id'], '_cost_price', true);
    6465
    65             if($single_cost_price)
     66            if($single_cost_price != null)
    6667            {
    6768                $total      += $product['total'];
     
    8788
    8889    /**
     90     * Calculate profit margins and save information to order
     91     *
     92     * @param   int $order_id   Calculate the profits from the order id
     93     */
     94    function cpfw_completed_order($order_id)
     95    {
     96        update_post_meta($order_id, '_order_profit', cpfw_calculate_order_profits(new WC_Order($order_id)));
     97    }
     98    add_action('woocommerce_order_status_completed', 'cpfw_completed_order');
     99
     100    /**
    89101     * Add profit collumn onto the order information
    90102     *
     
    93105    function cpfw_order_profit_information($order_id)
    94106    {
    95         $profits = cpfw_calculate_order_profits(new WC_Order($order_id));
     107        $profits = get_post_meta($order_id, '_order_profit', true);
    96108
    97109        if($profits != false) : ?>
     
    108120     * Modify table to include order profit margin
    109121     *
    110      * @param   array   $array  Table array used to generate email order information
     122     * @param   array           $array  Table array used to generate email order information
    111123     * @param   WC_Order    $order  The order
    112124     *
     
    130142
    131143    /**
    132      * Display profit margin on admin emails
    133      *
    134      * @param   WC_Order    $order  Email order object
    135      * @param bool  $sent_to_admin  Is email being sent to the admin or customer
     144     * Create new fields for variations
    136145     */
    137     function cpfw_display_profit_information($order, $sent_to_admin)
     146    function variation_settings_fields($loop, $variation_data, $variation)
    138147    {
    139         if($sent_to_admin)
    140         {
    141             add_filter('woocommerce_get_order_item_totals', 'cpfw_get_order_item_totals', 10, 2);
    142         }
     148        woocommerce_wp_text_input(
     149            array(
     150                'id'          => '_cost_price[' . $variation->ID . ']',
     151                'label'       => 'Variable Cost Price (' . get_woocommerce_currency_symbol() . ')',
     152                'value'       => get_post_meta($variation->ID, '_cost_price', true),
     153                'custom_attributes' => array(
     154                    'step'  => 'any',
     155                    'min'   => '0'
     156                )
     157            )
     158        );
    143159    }
    144     add_action('woocommerce_email_order_details', 'cpfw_display_profit_information', 10, 2);
     160    add_action('woocommerce_variation_options_pricing', 'variation_settings_fields', 10, 3);
     161
     162    /**
     163     * Save new fields for variations
     164     */
     165    function save_variation_settings_fields($post_id)
     166    {
     167        update_post_meta($post_id, '_cost_price', sanitize_text_field($_POST['_cost_price'][$post_id]));
     168    }
     169    add_action('woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2);
     170
     171    // Add admin dashboard widgets
     172    require_once('includes/widget.php');
    145173
    146174?>
  • cost-price-for-woocommerce/trunk/readme.txt

    r1938543 r2097821  
    2626= 1.0.0 (05/09/2018) =
    2727* Initial Release
     28
     29= 1.1.0 =
     30* Removed profits on admin emails
     31* Fixed bug causing profits being effected when changing cost price on old orders
     32* Fixed bug when inputting a cost price of 0
     33* Added support for variable products
     34* Added admin widget to display products without a cost price
Note: See TracChangeset for help on using the changeset viewer.