| 1 |
<?php |
| 2 |
/** |
| 3 |
* Support for WooCommerce |
| 4 |
* |
| 5 |
* @package event-post |
| 6 |
* @version 5.10.3 |
| 7 |
* @since 5.8.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace EventPost; |
| 11 |
|
| 12 |
\add_filter( 'woocommerce_product_tabs', '\EventPost\woocommerce_product_tabs' ); |
| 13 |
\add_filter( 'event-post-rich-result', '\EventPost\woocommerce_rich_result', 10, 2 ); |
| 14 |
|
| 15 |
function woocommerce_product_tabs($tabs){ |
| 16 |
$event = \EventPost()->retreive(); |
| 17 |
if($event && $event->start){ |
| 18 |
$tabs['event-post'] = [ |
| 19 |
'title' => __('Event', 'event-post'), |
| 20 |
'priority' => 20, |
| 21 |
'callback' => '\EventPost\product_event_tab', |
| 22 |
]; |
| 23 |
} |
| 24 |
return $tabs; |
| 25 |
} |
| 26 |
|
| 27 |
function product_event_tab($key, $tab){ |
| 28 |
$event = \EventPost()->retreive(); |
| 29 |
if($event){ |
| 30 |
\EventPost()->load_map_scripts(); |
| 31 |
include plugin_dir_path( __DIR__ ) . 'views/product-tab.php'; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
function woocommerce_rich_result($rich_data, $event){ |
| 36 |
$gmt_offset = get_option('gmt_offset '); |
| 37 |
if($event->post_type == 'product'){ |
| 38 |
$rich_data['offers'] = array( |
| 39 |
'@type'=>'Offer', |
| 40 |
'url'=>get_permalink($event->ID), |
| 41 |
'price'=>\EventPost()->get_price($event), |
| 42 |
'priceCurrency'=>get_woocommerce_currency(), |
| 43 |
'availability'=>'https://schema.org/InStock', |
| 44 |
'validFrom'=>str_replace(' ', 'T', $event->post_date_gmt).$gmt_offset, |
| 45 |
); |
| 46 |
} |
| 47 |
return $rich_data; |
| 48 |
} |
| 49 |
|