Advertisement
palsushobhan

wcfm-store-misc-shortcodes

Jan 9th, 2023
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.72 KB | None | 0 0
  1. add_shortcode('wcfm_store_distance', function() {
  2.     global $product, $WCFMmp;
  3.     if( !$product || !method_exists( $product, 'get_id' ) ) return;
  4.     $store_id = wcfm_get_vendor_id_by_post($product->get_id());
  5.     if(!$store_id) return;
  6.     if ( apply_filters( 'wcfmmp_is_allow_checkout_user_location', true ) && apply_filters( 'wcfm_is_allow_store_list_distance', true ) ) {
  7.         $distance = wcfmmp_get_user_vendor_distance( $store_id );  
  8.         $radius_unit   = isset( $WCFMmp->wcfmmp_marketplace_options['radius_unit'] ) ? $WCFMmp->wcfmmp_marketplace_options['radius_unit'] : 'km';
  9.         if( $distance ) {
  10.         ?>
  11.             <span class="store-distance">
  12.                 <i class="wcfmfa fa-map-marker-alt" aria-hidden="true"></i> <?php echo $distance . ' ' . $radius_unit . ' ' . __( 'away', 'wc-multivendor-marketplace' ); ?>
  13.         </span>
  14.         <?php
  15.         }
  16.     }
  17. });
  18. add_shortcode('wcfm_store_operating_hours', function() {
  19.     global $product;
  20.     if( !$product || !method_exists( $product, 'get_id' ) ) return;
  21.     $store_id = wcfm_get_vendor_id_by_post($product->get_id());
  22.     if(!$store_id) return;
  23.     if( apply_filters( 'wcfm_is_pref_store_hours', true ) && $store_id && wcfm_is_vendor( $store_id ) ) {
  24.         $wcfm_vendor_store_hours = get_user_meta( $store_id, 'wcfm_vendor_store_hours', true );
  25.         if( !$wcfm_vendor_store_hours || !isset($wcfm_vendor_store_hours['enable']) || $wcfm_vendor_store_hours['enable']!=='yes') {
  26.             return;
  27.         }
  28.         $todays_number = date('N') - 1;
  29.         $wcfm_store_hours_off_days  = isset( $wcfm_vendor_store_hours['off_days'] ) ? $wcfm_vendor_store_hours['off_days'] : array();
  30.         if(!empty($wcfm_store_hours_off_days) && in_array($todays_number, $wcfm_store_hours_off_days)) {
  31.             return;
  32.         }
  33.         $wcfm_store_hours_day_times = isset( $wcfm_vendor_store_hours['day_times'] ) ? $wcfm_vendor_store_hours['day_times'] : array();
  34.         if( empty( $wcfm_store_hours_day_times[$todays_number] )) return;  
  35.         $todays_slots = $wcfm_store_hours_day_times[$todays_number];
  36.         $time_html = '';
  37.         foreach( $todays_slots as $time_slot ) {
  38.             if( empty( $time_slot['start'] ) || empty( $time_slot['end'] ) ) continue;         
  39.             $time_html .= '<br />'. date_i18n( wc_time_format(), strtotime( $time_slot['start'] ) ) . " - " . date_i18n( wc_time_format(), strtotime( $time_slot['end'] ) );
  40.         }
  41.         if($time_html) {
  42.         ?>
  43.             <div class="wcfmmp_store_hours">
  44.                 <span class="wcfmmp-store-hours widget-title"><span class="wcfmfa fa-clock"></span> <?php echo date('l'); ?>:</span>   
  45.                 <?php echo $time_html; ?>
  46.             </div>
  47.         <?php
  48.         }
  49.     }
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement