Wordpress WooCommerce store - Subtitle under Products Titles

Pri*_*ima 4 php wordpress hyperlink subtitle woocommerce

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:

  • 创建一个字幕区域(将其命名为REG。NO :),这样我不仅可以写产品的标题,还可以写字幕。因此,当您打开一个产品页面时,它将像:

This_is_my_product_title REG.NO: this_is_my_reg_no

  • 另一个问题是,我需要一个REG.NO :(字幕)作为指向其他网站的外部超链接。

非常感谢任何可以帮助我的人。

Ana*_*hah 5

如果您想采用纯WooCommerce方式,这就是要点。

1-添加自定义字段 (此代码包含在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' ) 
    )
);

}
Run Code Online (Sandbox Code Playgroud)

该字段将显示为此屏幕抓图所示:http : //i.imgur.com/fGC86DA.jpg

2-保存产品时保存字段数据。(此代码在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 ) );

}
Run Code Online (Sandbox Code Playgroud)

3-编辑单个产品模板并显示该字段的值

<?php 
global $post;
echo get_post_meta( $post->ID, '_subtitle', true );
?>
Run Code Online (Sandbox Code Playgroud)