Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Created April 9, 2013 23:23
Show Gist options
  • Save ChromeOrange/5350273 to your computer and use it in GitHub Desktop.
Save ChromeOrange/5350273 to your computer and use it in GitHub Desktop.
Create a cost price field for simple products, add this to functions.php
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'] ) );
}
@AlexRodriguezS
Copy link

Hi, I was looking for a solution like this one to display a price in MXN Pesos and a price in USD.

How did you displayed the custom price in the frontend? Does it affect the cart price?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment