SHARE
TWEET

Untitled

a guest Jun 6th, 2017 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action( 'woocommerce_product_options_general_product_data', 'wc_custom_add_custom_fields' );
  2.  
  3. add_action( 'woocommerce_product_options_general_product_data', 'wc_custom_add_custom_fields' );
  4. function wc_custom_add_custom_fields() {
  5.     // Print a custom text field
  6.     woocommerce_wp_text_input( array(
  7.         'id' => '_my_text_field',
  8.         'label' => 'Lisaväli',
  9.         'description' => 'This is a custom field, you can write here anything you want.',
  10.         'desc_tip' => 'true',
  11.         'placeholder' => 'Sisesta kogus'
  12.     ) );
  13. }
  14.  
  15. add_action( 'woocommerce_process_product_meta', 'wc_custom_save_custom_fields' );
  16. function wc_custom_save_custom_fields( $post_id ) {
  17.     if ( ! empty( $_POST['_my_text_field'] ) ) {
  18.         update_post_meta( $post_id, '_my_text_field', esc_attr( $_POST['_my_text_field'] ) );
  19.     }
  20. }
  21. // Show on frontend
  22. add_action( 'woocommerce_single_product_summary', 'print_my_cf_value', 20 );
  23. function print_my_cf_value() {
  24.     global $product;
  25.     echo '<p>' . esc_html( get_post_meta( $product->ID, '_my_text_field', true ) ) . '</p>';
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top