Site logo

Archived topic

shortcode for woocommerce date?

3 replies · Started by nomadiceman on November 26, 2021

Viewing posts 1–4 of 4

hi guys,

I'm starting my first eCommerce site so I apologise if my questions are a little stupid

I've got the FooEvents plugin installed and really would like to pull the event date into the block elements header

do you know what the shortcode is for this? I'm not sure what I am trying to find. is it even possible?

thank you for your help

I've found this snippet on the FooEvents website


function fooevents_display_date_on_single() {
  global $post;
  $product = wc_get_product( $post->ID );
  $start_date = $product->get_meta( 'WooCommerceEventsDate' );
  $end_date = $product->get_meta( 'WooCommerceEventsEndDate' );
  if ( $end_date ) {
    printf(
      '<h3>%s</h3>',
      esc_html( $start_date . ' - ' . $end_date )
    );
  } else if( $start_date ) {
    printf(
      '<h3>%s</h3>',
      esc_html( $start_date )
    );
  }
}
add_action( 'woocommerce_single_product_summary', 'fooevents_display_date_on_single' );

does that help?

or this


function fooevents_display_time_in_shop_listing() {
global $post;
if (is_front_page() || is_home() || is_shop() || is_product_category() || is_product_tag()) {
echo '<div class="fooevents-date">';
echo get_post_meta($post->ID, 'WooCommerceEventsHour', true).':';
echo get_post_meta($post->ID, 'WooCommerceEventsMinutes', true). ' ';
echo get_post_meta($post->ID, 'WooCommerceEventsPeriod', true);
echo '</div>';
}
}
add_filter( 'woocommerce_after_shop_loop_item_title', 'fooevents_display_time_in_shop_listing', 35 );

Hi there,

I'm not familiar with FooEvents plugin unfortunately.

I would recommend checking with their support team first to see if there is a shortcode you can use.

You can always test the code you've found above by using the Code Snippets plugin:
Adding PHP: https://docs.generatepress.com/article/adding-php/

The first one is adding some content to the woocommerce_single_product_summary hook and the second one is a filter for woocommerce_after_shop_loop_item_title.

This archived topic is closed to new replies.