Advertisement
daymobrew

Add Supplier Code field input @ product edit page

Jan 22nd, 2018
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Add Supplier Code field
  4. Plugin URI: https://www.facebook.com/groups/advanced.woocommerce/permalink/1968581709822905/
  5. Description: Request on Facebook Advanced WooCommerce group - add Supplier Code field.
  6. Author: Damien Carbery
  7. Author URI: http://www.damiencarbery.com
  8. Version: 0.1
  9. */
  10.  
  11. // 1. Add Supplier Code field input @ product edit page
  12.  
  13. add_action( 'woocommerce_product_options_sku', 'bbloomer_add_supplier_code_to_products' );        
  14.  
  15. function bbloomer_add_supplier_code_to_products() {
  16.     woocommerce_wp_text_input( array(
  17.                         'id' => '_supplier_code',
  18.                         'class' => 'short wc_input_price',
  19.                         'label' => __( 'Supplier Code', 'woocommerce' )
  20.                         )
  21.                         );
  22. }
  23.  
  24. // -----------------------------------------
  25. // 2. Save Supplier Code field via custom field
  26.  
  27. add_action( 'save_post', 'bbloomer_save_supplier_code' );
  28.  
  29. function bbloomer_save_supplier_code( $product_id ) {
  30.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  31.         return;
  32.  
  33.     if ( isset( $_POST['supplier_code'] ) ) {
  34.         if ( is_numeric( $_POST['_supplier_code'] ) )
  35.             update_post_meta( $product_id, '_supplier_code', $_POST['supplier_code'] );
  36.     } else delete_post_meta( $product_id, '_supplier_code' );
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement