Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @regianesouza

    In order to put a date and time of when a product is published, you can put this custom code on your functions.php file in Appearance Theme File Editor.

    add_action( 'woocommerce_after_shop_loop_item_title', 'display_post_date_and_hours', 20 );
    
    function display_post_date_and_hours() {
        global $product;
    
        // Get the product's published date
        $product_date = $product->get_date_created();
    
        // Format the product date and time
        $formatted_date = $product_date->date( 'F j, Y' );
        $formatted_time = $product_date->date( 'g:i a' );
    
        // Output the formatted product date and time
        echo '<p>Published on ' . $formatted_date . ' at ' . $formatted_time . '</p>';
    }
    

    Please note that we can’t provide support for code customization as per our support policy. Still, if you need customization, we do our best to offer advice and direct you to appropriate resources. Based on the feedback we get from our customers, we highly recommend contacting one of the services on our Customization page.

    I hope this helps!

    Thread Starter Regiane Souza

    (@regianesouza)

    Hi @aguinaldodarla, thanks for reply!

    It is exactly I need, but, it is showing only on the shop page, it isn’t showing on the product page. There is a way to show it on the product page too?

    Hi @regianesouza

    You can use this code below instead to show it on both pages:

    // Display on shop page
    add_action( 'woocommerce_after_shop_loop_item_title', 'display_post_date_and_hours_shop', 20 );
    
    // Display on single product page
    add_action( 'woocommerce_single_product_summary', 'display_post_date_and_hours_product', 15 );
    
    function display_post_date_and_hours_shop() {
        global $product;
    
        // Get the product's published date
        $product_date = $product->get_date_created();
    
        // Format the product date and time
        $formatted_date = $product_date->date( 'F j, Y' );
        $formatted_time = $product_date->date( 'g:i a' );
    
        // Output the formatted product date and time
        echo '<p>Published on ' . $formatted_date . ' at ' . $formatted_time . '</p>';
    }
    
    function display_post_date_and_hours_product() {
        global $product;
    
        // Get the product's published date
        $product_date = $product->get_date_created();
    
        // Format the product date and time
        $formatted_date = $product_date->date( 'F j, Y' );
        $formatted_time = $product_date->date( 'g:i a' );
    
        // Output the formatted product date and time
        echo '<p>Published on ' . $formatted_date . ' at ' . $formatted_time . '</p>';
    }

    Please let us know if you still need assistance.

    Cheers,

    Thread Starter Regiane Souza

    (@regianesouza)

    Oh @aguinaldodarla, Thanks so much! It worked perfectly.

    A last question about that, please:

    Is it possible formatting the font to a small size, to show small in both pages?

    Thread Starter Regiane Souza

    (@regianesouza)

    Oh?@aguinaldodarla, I already get to formatting that.

    Thank you so much! ??

    Hi @regianesouza

    That’s great! I’m happy that everything now works, and we’re able to help. I’ll mark this thread as resolved, but please don’t hesitate to start a new topic if you have any more questions down the line.

    If you have a few minutes, we’d love if you could leave us a review: https://www.ads-software.com/support/plugin/woocommerce/reviews/

    Have a fantastic day!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Post hour on Woocommerce’ is closed to new replies.