WooCommece cost price custom field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cost price | |
add_action('woocommerce_product_options_pricing', 'cost_price'); | |
function cost_price() { | |
woocommerce_wp_text_input( | |
array( | |
'id' => '_cost_price', | |
'class' => 'wc_input_price short', | |
'label' => __('Cost price', 'woocommerce').' ('.get_woocommerce_currency_symbol().')', | |
'type' => 'text', | |
) | |
); | |
} | |
add_action('woocommerce_process_product_meta_simple', 'save_cost_price'); | |
function save_cost_price($post_id) { | |
global $wpdb, $woocommerce, $woocommerce_errors; | |
$cost_price = $_POST['_cost_price']; | |
update_post_meta($post_id, '_cost_price', esc_attr($_POST['_cost_price'])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment