I've been reading WP forums and trying different plugins for over a week now with no luck, so I decided to give it a try here.
I'm creating a WP website with a premium theme, that supports a woocommerce. What I need to do is the following:
This_is_my_product_title
REG.NO: this_is_my_reg_no
Greatest thanks to anyone who could help me out.
If you want to go pure WooCommerce way, here's the gist.
1 - Add custom field ( this code goes in functions.php )
add_action( 'woocommerce_product_options_general_product_data', 'my_custom_field' );
function my_custom_field() {
woocommerce_wp_text_input(
array(
'id' => '_subtitle',
'label' => __( 'Subtitle', 'woocommerce' ),
'placeholder' => 'Subtitle....',
'description' => __( 'Enter the subtitle.', 'woocommerce' )
)
);
}
The field will appear as shown in this screen grab : http://i.imgur.com/fGC86DA.jpg
2 - Save the field's data when product is saved. ( this code goes in functions.php )
add_action( 'woocommerce_process_product_meta', 'my_custom_field_save' );
function my_custom_field_save( $post_id ){
$subtitle = $_POST['_subtitle'];
if( !empty( $subtitle ) )
update_post_meta( $post_id, '_subtitle', esc_attr( $subtitle ) );
}
3 - Edit single product template and display the field's value
<?php
global $post;
echo get_post_meta( $post->ID, '_subtitle', true );
?>