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:
This_is_my_product_title
REG.NO: this_is_my_reg_no
非常感谢任何可以帮助我的人。
如果您想采用纯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)
| 归档时间: |
|
| 查看次数: |
5481 次 |
| 最近记录: |