Skip to content

Instantly share code, notes, and snippets.

@emilstahl
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilstahl/2e86a3ae706b47d82bb1 to your computer and use it in GitHub Desktop.
Save emilstahl/2e86a3ae706b47d82bb1 to your computer and use it in GitHub Desktop.
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