Created
February 17, 2019 16:35
-
-
Save Musilda/2f72a8b983ffbad6433157fda695e860 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
add_action( 'woocommerce_product_options_general_product_data', 'toret_custom_product_field' ); | |
function toret_custom_product_field(){ | |
woocommerce_wp_text_input( | |
array( | |
'id' => 'custom_product_text', | |
'label' => __( 'Produkt text', 'toret-skoleni' ), | |
'placeholder' => 'Produkt text', | |
'desc_tip' => 'true', | |
'description' => __( 'Produkt text', 'toret-skoleni' ) | |
) | |
); | |
} | |
add_action('save_post', 'woo_add_custom_general_fields_save' ); | |
function woo_add_custom_general_fields_save( $post_id ){ | |
//Check autosave | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
return $post_id; | |
} | |
//Don't update on Quick Edit | |
if ( defined( 'DOING_AJAX') ) { | |
return $post_id; | |
} | |
//Don't update on Bulk Edit | |
if ( !empty( $_REQUEST['bulk_edit'] ) ) { | |
return $post_id; | |
} | |
if( get_post_type( $post_id ) != 'product' ){ | |
return $post_id; | |
} | |
if( !empty( $_POST['custom_product_text'] ) ){ | |
update_post_meta( $post_id, 'custom_product_text', $_POST['custom_product_text'] ); | |
} | |
} | |
add_action( 'woocommerce_single_product_summary', 'toret_display_meta_data' , 12 ); | |
function toret_display_meta_data(){ | |
global $post; | |
$text = get_post_meta( $post->ID, 'custom_product_text', true ); | |
echo '<p>'.$text.'</p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment