Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Add Supplier Code field
- Plugin URI: https://www.facebook.com/groups/advanced.woocommerce/permalink/1968581709822905/
- Description: Request on Facebook Advanced WooCommerce group - add Supplier Code field.
- Author: Damien Carbery
- Author URI: http://www.damiencarbery.com
- Version: 0.1
- */
- // 1. Add Supplier Code field input @ product edit page
- add_action( 'woocommerce_product_options_sku', 'bbloomer_add_supplier_code_to_products' );
- function bbloomer_add_supplier_code_to_products() {
- woocommerce_wp_text_input( array(
- 'id' => '_supplier_code',
- 'class' => 'short wc_input_price',
- 'label' => __( 'Supplier Code', 'woocommerce' )
- )
- );
- }
- // -----------------------------------------
- // 2. Save Supplier Code field via custom field
- add_action( 'save_post', 'bbloomer_save_supplier_code' );
- function bbloomer_save_supplier_code( $product_id ) {
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
- return;
- if ( isset( $_POST['supplier_code'] ) ) {
- if ( is_numeric( $_POST['_supplier_code'] ) )
- update_post_meta( $product_id, '_supplier_code', $_POST['supplier_code'] );
- } else delete_post_meta( $product_id, '_supplier_code' );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement