Skip to content

Instantly share code, notes, and snippets.

@ofernandolopes
Forked from ChromeOrange/gist:5350273
Last active August 29, 2015 14:21
Show Gist options
  • Save ofernandolopes/3bacb196151e75e25e36 to your computer and use it in GitHub Desktop.
Save ofernandolopes/3bacb196151e75e25e36 to your computer and use it in GitHub Desktop.
WooCommerce - Create a cost price field for simple products
add_action('woocommerce_product_options_pricing','custom_cost_price');
function custom_cost_price() {
woocommerce_wp_text_input( array( 'id' => '_cost_price', 'class' => 'wc_input_price short', 'label' => __( 'Cost Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')', 'type' => 'number', 'custom_attributes' => array(
'step' => 'any',
'min' => '0'
) ) );
}
add_action('woocommerce_process_product_meta_simple', 'save_custom_cost_price');
function save_custom_cost_price($post_id) {
global $wpdb, $woocommerce, $woocommerce_errors;
update_post_meta( $post_id, '_cost_price', stripslashes( $_POST['_cost_price'] ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment