Created
March 13, 2019 10:58
-
-
Save waqashassan98/e17435b214c63b79868fd8465ae1dc4d to your computer and use it in GitHub Desktop.
Custom field for woocommerce product
This file contains hidden or 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
/** | |
* Create Custom Members Price Field for Woocommerce Product | |
* @since 1.0.0 | |
*/ | |
function nb_create_member_price_field() { | |
$args = array( | |
'id' => 'member_price', | |
'label' => __( 'Members Price', 'cfwc' ), | |
'class' => 'nb-custom-field', | |
'desc_tip' => true, | |
'description' => __( 'The price for members.', 'rider-ways' ), | |
); | |
woocommerce_wp_text_input( $args ); | |
} | |
add_action( 'woocommerce_product_options_general_product_data', 'nb_create_member_price_field' ); | |
/** | |
* Save Custom Members Price Field for Woocommerce Product | |
* @since 1.0.0 | |
*/ | |
function nb_save_custom_field( $post_id ) { | |
$product = wc_get_product( $post_id ); | |
$title = isset( $_POST['member_price'] ) ? $_POST['member_price'] : ''; | |
$product->update_meta_data( 'member_price', sanitize_text_field( $title ) ); | |
$product->save(); | |
} | |
add_action( 'woocommerce_process_product_meta', 'nb_save_custom_field' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment