Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

add custom text after title of products on achive page

//Register the product custom field

/// for add this in advance tab we need to use 'woocommerce_product_options_advanced'
add_action( 'woocommerce_product_options_general_product_data', 'my_woocommerce_product_subheading' );

function my_woocommerce_product_subheading() {
    $args = array(
        'label' => 'Subheading', // Text in Label
        'placeholder' => 'My Subheading',
        'id' => 'product_subheading', // required
        'name' => 'product_subheading',
        'desc_tip' => 'The product subheading',
    );
    woocommerce_wp_text_input( $args );
}

//Save the custom field as product custom post meta
add_action( 'woocommerce_process_product_meta', 'my_woocommerce_save_product_subheading' );

function my_woocommerce_save_product_subheading( $post_id ) {
    $product = wc_get_product( $post_id );
    $title = isset( $_POST['product_subheading'] ) ? $_POST['product_subheading'] : '';
    $product->update_meta_data( 'product_subheading', sanitize_text_field( $title ) );
    $product->save();
}

//Display the custom field on product page loop below the title
add_action( 'woocommerce_after_shop_loop_item_title', 'subheading_display_below_title', 2 );
function subheading_display_below_title(){
    global $product;

    // Get the custom field value
    $subheading = get_post_meta( $product->get_id(), 'product_subheading', true );

    // Display
    if( ! empty($subheading) ){
        echo '<p class="subheading">'.$subheading.'</p>';
    }
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: R barplots ggplot 
Typescript :: typescript allow object subset of interface 
Typescript :: Restrict users to see only his own contacts odoo 
Typescript :: allow specific string in type 
Typescript :: css proferties throught ts 
Typescript :: type for object props 
Typescript :: translate a vector 
Typescript :: how to invert sortField primeng 
Typescript :: Highcharts error #17: www.highcharts.com/errors/17/?missingModuleFor=candlestick - missingModuleFor: candlestick 
Typescript :: typescript type casting 
Typescript :: In default Laravel installation, what is the default API Rate Limit? In other words, how many requests can be done in one minute? 
Typescript :: react static typescript properties 
Typescript :: ts repeat string 
Typescript :: typescript array data structure 
Typescript :: components of .net framework 
Typescript :: typescript enum get key by value 
Typescript :: what version of python supports kivy 
Typescript :: based on previous make validation for required in reactive forms 
Typescript :: splice typescript array 
Typescript :: python search all txts in a folder 
Typescript :: top data scientists in the world 
Typescript :: install vsts client version 14.102.0 
Cpp :: c++ show time elapsed 
Cpp :: select one random element of a vector in c++ 
Cpp :: string hex to int c++ 
Cpp :: c++ flush stdin 
Cpp :: remove all element of vector c++ 
Cpp :: eosio parse string 
Cpp :: inreament operator 
Cpp :: file handling 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =