Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Woocommerce – Latest modified date

Previously I have added the PHP Snippet to make my single product page shows the latest modified date.

However, I have to rebuild the single product page with Elementor pro (Theme builder) for some reason. The code is not working anymore on the single product page.

Appreciate it if anyone could help with this.
Thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    function woocommerce_product_date() {
    // Get the global product object
    global $product;

    // Is a WC product
    if ( is_a( $product, 'WC_Product' ) ) {
        // Output date created & date modified
        // 
        echo "<br>";
        echo "<br>";
        echo sprintf( '<p>' .__ ( 'Date modified: %s', 'woocommerce' ) . '</p>', $product->get_date_modified()->date( 'Y-m-d' ) );
    }
}
// Display on single product page
add_action( 'woocommerce_single_product_summary', 'woocommerce_product_date', 10, 0 );
// Display on archive/shop page
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_product_date', 10, 0 );

>Solution :

Working with Elementor and the standard WooCommerce hooks can be a hassle because some hooks don’t exist or need to be placed in the single product template.
You have 2 alternative options:

  1. Make sure that this hook is there by placing the correct product widget in your template which contains this hook.

  2. Modify your code: Create a shortcode instead of a hook and place the shortcode where you want in your template:

    add_shortcode( 'my_custom_product_date', woocommerce_product_date' );

Put [my_custom_product_date]in your Elementor template.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading