-
-
Save ofernandolopes/3bacb196151e75e25e36 to your computer and use it in GitHub Desktop.
WooCommerce - Create a cost price field for simple products
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
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