Add a custom field value below product title in WooCommerce archives pages

前端 未结 2 591
夕颜
夕颜 2021-01-01 04:12

In WooCommerce I would like to add custom text to my products display, that will be grabbed from a custom field in product\'s edit page.

This is how it looks now:

2条回答
  •  伪装坚强ぢ
    2021-01-01 04:35

    Updated:

    Try this custom hooked function, that will display your custom field value below product title:

    add_action( 'woocommerce_after_shop_loop_item_title', 'custom_field_display_below_title', 2 );
    function custom_field_display_below_title(){
        global $product;
    
        // Get the custom field value
        $custom_field = get_post_meta( $product->get_id(), '_custom_product_text_field', true );
    
        // Display
        if( ! empty($custom_field) ){
            echo '

    '.$custom_field.'

    '; } }

    Code goes in function.php file of your active child theme (or active theme).

    It should work.

提交回复
热议问题