Changeset 2097821
- Timestamp:
- 05/30/2019 10:21:09 AM (7 years ago)
- Location:
- cost-price-for-woocommerce/trunk
- Files:
-
- 2 added
- 2 edited
-
cost-price-for-woocommerce.php (modified) (7 diffs)
-
includes (added)
-
includes/widget.php (added)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cost-price-for-woocommerce/trunk/cost-price-for-woocommerce.php
r1938543 r2097821 3 3 /** 4 4 * Plugin Name: Cost Price for WooCommerce 5 * Description: This plugin lets the admin input the cost price for allproducts.5 * Description: This plugin lets the admin calculate the profits they're making on orders and specific products. 6 6 * Author: Lewis Self 7 * Version: 1.0.0 7 * Author URI: https://www.lewisself.co.uk 8 * Version: 1.1.0 8 9 * License: GPL2+ 9 10 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 10 11 * 11 12 * WC requires at least: 3.0.0 12 * WC tested up to: 3. 4.413 * WC tested up to: 3.6.4 13 14 */ 14 15 … … 47 48 * Calculates order profits 48 49 * 49 * @param WC_Order $order The order which to calculate the profits50 * @param WC_Order $order The order which to calculate the profits 50 51 * 51 52 * @return bool | int The calculated profit. If not possible to calculate, return false … … 63 64 $single_cost_price = get_post_meta($product['product_id'], '_cost_price', true); 64 65 65 if($single_cost_price )66 if($single_cost_price != null) 66 67 { 67 68 $total += $product['total']; … … 87 88 88 89 /** 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 /** 89 101 * Add profit collumn onto the order information 90 102 * … … 93 105 function cpfw_order_profit_information($order_id) 94 106 { 95 $profits = cpfw_calculate_order_profits(new WC_Order($order_id));107 $profits = get_post_meta($order_id, '_order_profit', true); 96 108 97 109 if($profits != false) : ?> … … 108 120 * Modify table to include order profit margin 109 121 * 110 * @param array $array Table array used to generate email order information122 * @param array $array Table array used to generate email order information 111 123 * @param WC_Order $order The order 112 124 * … … 130 142 131 143 /** 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 136 145 */ 137 function cpfw_display_profit_information($order, $sent_to_admin)146 function variation_settings_fields($loop, $variation_data, $variation) 138 147 { 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 ); 143 159 } 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'); 145 173 146 174 ?> -
cost-price-for-woocommerce/trunk/readme.txt
r1938543 r2097821 26 26 = 1.0.0 (05/09/2018) = 27 27 * 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.