5

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:

  • Create a subtitle area (which would be named REG. NO:), so I could not only write Title of the product, but subtitle also. So when you would open a single product page, it would be like:

This_is_my_product_title REG.NO: this_is_my_reg_no

  • another issue is, I would need a REG.NO: (subtitle) to be an external hyperlink to a different website.

Greatest thanks to anyone who could help me out.

Prima
  • 101
  • 1
  • 1
  • 4

3 Answers3

5

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 );
?>
Anand Shah
  • 14,575
  • 16
  • 72
  • 110
  • Thank you! It almost works, I can get a subtitle to show on my edit product page, however, when I enter the text under subtitle it's not saved and neither would show on my product page. EDIT: there was a typo under your 2. point. id is _sub_title and not _subtitle. However, the subtitle does not show UNDER the title. – Prima Aug 18 '15 at 12:22
  • Did you edit the single product template that displays the title and add the code shown in point #3? – Anand Shah Aug 18 '15 at 14:10
  • i tried both single product and content single product. – Prima Aug 18 '15 at 15:04
  • Would be possible to also get a personal email contact? I might have more payable work for you in the future. – Prima Aug 18 '15 at 15:08
  • Please send me your email address and I'll contact you. – Anand Shah Aug 19 '15 at 06:32
2

Ok so for everyone else who might have the same problem. Although both of options posted already are worth considering and will definitely save them as favorites because I'm sure I will need this in the future, this is the solution that worked best for me.

Although I'm trying to use as few plugins as possible, I ultimately decided to go with KIA SUBTITLE plugin. Then, you have to write this code in your functions.php:

function kia_add_subtitle_link_to_woocommerce(){
if( function_exists( 'the_subtitle' ) ){

    $link = the_subtitle( '<h2 class="subtitle"><a href="%s" title="%s">', '</a></h2>', false );

    printf( $link, get_permalink(), sprintf( __( 'Permalink to %s', 'your-text-domain' ), get_the_title() ) );
}
}

add_action( 'some_custom_hook', 'kia_add_subtitle_link_to_woocommerce' );

I used the following hook:

add_action( 'woocommerce_single_product_summary', 'kia_add_subtitle_link_to_woocommerce' );
Prima
  • 101
  • 1
  • 1
  • 4
1

You can use Advanced custom field plugin to create extra field in add product for REG NO

and you simple get field value on single page using the_field('name_u_give')

or you can also add post meta for post type product

Ravinder Kumar
  • 902
  • 10
  • 29
  • Thank you for the feedback. This all sounds nice and easy, but unfortunately I have no knowledge in coding and this is my first WP website. I can give it a try and read about custom fields and learn on the fly, but would appreciate a bit more of a in-depth answer. Thanks though, will research it right away and write here if I'm stuck on something. – Prima Aug 18 '15 at 11:01