Advertisement
xah

cost price field

xah
Jun 9th, 2020 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. // Not mine
  2.  
  3. add_action( 'woocommerce_product_options_pricing', 'wc_cost_product_field' );
  4. function wc_cost_product_field() {
  5.     woocommerce_wp_text_input( array( 'id' => 'cost_price', 'class' => 'wc_input_price short', 'label' => __( 'Cost Price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')' ) );
  6. }
  7.  
  8. add_action( 'save_post', 'wc_cost_save_product' );
  9. function wc_cost_save_product( $product_id ) {
  10.  
  11.      // stop the quick edit interferring as this will stop it saving properly, when a user uses quick edit feature
  12.      if (wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce'))
  13.         return;
  14.  
  15.     // If this is a auto save do nothing, we only save when update button is clicked
  16.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  17.         return;
  18.     if ( isset( $_POST['cost_price'] ) ) {
  19.         if ( is_numeric( $_POST['cost_price'] ) )
  20.             update_post_meta( $product_id, 'cost_price', $_POST['cost_price'] );
  21.     } else delete_post_meta( $product_id, 'cost_price' );
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement