Wordpress WooCommerce商店 - 产品标题下的字幕(Wordpress WooCommerce store - Subtitle under Products Titles)

我一直在阅读WP论坛并尝试不同的插件超过一个星期,现在没有运气,所以我决定在这里尝试一下。

我正在创建一个高级主题的WP网站,支持woocommerce 。 我需要做的是以下内容:

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

This_is_my_product_title REG.NO: this_is_my_reg_no

另一个问题是,我需要REG.NO :(副标题)作为到不同网站的外部超链接。

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

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.

最满意答案

如果你想采用纯粹的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' ) ) ); }

该字段将显示在此屏幕抓取中: 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 ) ); }

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

<?php global $post; echo get_post_meta( $post->ID, '_subtitle', true ); ?>

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 ); ?>

更多推荐