Display the modified date of every product on Woocommerce shop page

我是研究僧i 提交于 2020-08-10 19:40:57

问题


In WooCommerce I would like to display products modified date on every product on archive pages as shop.

Any track is helpful.


回答1:


The following will display the product modified date on shop and archive pages (see date format):

add_action( 'woocommerce_after_shop_loop_item', 'after_shop_loop_item_action_callback', 20 );
function after_shop_loop_item_action_callback() {
    global $product;

    echo '<br><span class="date_modified">' . $product->get_date_modified()->date('F j, Y, g:i a') . '</span>';
}

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




回答2:


Paste that code in function.php

function show_last_modified_date( $content ) {
    $original_time = get_the_time('U');
    $modified_time = get_the_modified_time('U');
    if ($modified_time >= $original_time + 86400) {
        $updated_time = get_the_modified_time('h:i a');
        $updated_day = get_the_modified_time('F jS, Y');
        $modified_content .= '<p class="last-modified">This post was most recently updated on '. $updated_day . '</p>';
    }
    $modified_content .= $content;
    return $modified_content;
}
add_filter( 'the_content', 'show_last_modified_date' );


来源:https://stackoverflow.com/questions/55450128/display-the-modified-date-of-every-product-on-woocommerce-shop-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!