Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_product_options_general_product_data', 'wc_custom_add_custom_fields' );
- add_action( 'woocommerce_product_options_general_product_data', 'wc_custom_add_custom_fields' );
- function wc_custom_add_custom_fields() {
- // Print a custom text field
- woocommerce_wp_text_input( array(
- 'id' => '_my_text_field',
- 'label' => 'Lisaväli',
- 'description' => 'This is a custom field, you can write here anything you want.',
- 'desc_tip' => 'true',
- 'placeholder' => 'Sisesta kogus'
- ) );
- }
- add_action( 'woocommerce_process_product_meta', 'wc_custom_save_custom_fields' );
- function wc_custom_save_custom_fields( $post_id ) {
- if ( ! empty( $_POST['_my_text_field'] ) ) {
- update_post_meta( $post_id, '_my_text_field', esc_attr( $_POST['_my_text_field'] ) );
- }
- }
- // Show on frontend
- add_action( 'woocommerce_single_product_summary', 'print_my_cf_value', 20 );
- function print_my_cf_value() {
- global $product;
- echo '<p>' . esc_html( get_post_meta( $product->ID, '_my_text_field', true ) ) . '</p>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement