Skip to content

Instantly share code, notes, and snippets.

@emilstahl
Last active Aug 29, 2015
Embed
What would you like to do?
WooCommece cost price custom field
// 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