0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WordPressのプラグインEventsManagerで予約受付開始/終了時刻を表示させた

Last updated at Posted at 2021-04-02

結論

子テーマの functions.php に以下を追加する

functions.php
function my_em_custom_placeholders($replace, $EM_Event, $result){
  switch( $result ){
    case '#_TICKETSTART': /*受付開始時刻*/
		$Tickets = $EM_Event->get_tickets();
		if( !empty($Tickets)){
			$Ticket = $Tickets->get_first();
			$replace = $Ticket->start();
		}
		else{
			$replace = 'このイベントはオンライン予約できません';
		}
      break;
	case '#_TICKETSTOP': /*受付終了時刻*/
		$Tickets = $EM_Event->get_tickets();
		if( !empty($Tickets)){
			$Ticket = $Tickets->get_first();
			$replace = $Ticket->end();
		}
		else{
			$replace = 'このイベントはオンライン予約できません';
		}
	  break;
   }
  return $replace;
}
add_filter('em_event_output_placeholder','my_em_custom_placeholders',1,3);

このコードによって #_TICKETSTART と #_TICKETSTOP というプレースホルダーが作成されるので、WordPress管理者メニューの
[イベント]=>[設定]=>[フォーマット]=>[イベント]=>[イベント詳細ページの書式]
とかに

{has_bookings}
<table>
<tbody>
<tr>
<td>予約受付開始―終了時刻</td><td><strong>#_TICKETSTART</strong></br>―#_TICKETSTOP</td>
</tr>
</tbody>
</table>
{/has_bookings}

こんな風に入力すれば、そのイベントが予約可能なときのみ開始時間が表示される。

参考

「Events Manager」でオリジナルのプレースホルダーを追加する | WordPressの勉強がてら

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?