| 1 |
<?php |
| 2 |
/** |
| 3 |
* WooCommerce Product |
| 4 |
* |
| 5 |
* @package Timetics |
| 6 |
*/ |
| 7 |
namespace Timetics\Core\Integrations\Woocommerce; |
| 8 |
|
| 9 |
defined( 'ABSPATH' ) || exit; |
| 10 |
|
| 11 |
/** |
| 12 |
* WooCommerce Product class |
| 13 |
*/ |
| 14 |
class Product { |
| 15 |
/** |
| 16 |
* Creat product for woocommer |
| 17 |
* |
| 18 |
* @return bool |
| 19 |
*/ |
| 20 |
public function create( $meeting ) { |
| 21 |
$product_id = $meeting->get_wc_product_id(); |
| 22 |
|
| 23 |
if ( $product_id ) { |
| 24 |
$product = wc_get_product( $product_id ); |
| 25 |
} else { |
| 26 |
$product = new \WC_Product_Simple (); |
| 27 |
} |
| 28 |
|
| 29 |
$product_category = get_term_by( 'slug', 'timetics-meeting', 'product_cat' ); |
| 30 |
$product_category_id = ! empty( $product_category ) ? $product_category->term_id : 0; |
| 31 |
|
| 32 |
$product->set_name( $meeting->get_name() ); |
| 33 |
$product->set_short_description( $meeting->get_description() ); |
| 34 |
$product->set_price( $meeting->get_price() ); |
| 35 |
$product->set_status( 'publish' ); |
| 36 |
$product->set_category_ids( [$product_category_id] ); |
| 37 |
|
| 38 |
$product->update_meta_data( 'timetics_meeting_id', $meeting->get_id() ); |
| 39 |
|
| 40 |
// Store meeting details as product meta for checkout/email display |
| 41 |
$product->update_meta_data( 'timetics_duration', $meeting->get_duration() ); |
| 42 |
$product->update_meta_data( 'timetics_timezone', $meeting->get_timezone() ); |
| 43 |
|
| 44 |
$product_id = $product->save(); |
| 45 |
|
| 46 |
$meeting->update( [ |
| 47 |
'wc_product_id' => $product->get_id(), |
| 48 |
] ); |
| 49 |
|
| 50 |
return $product_id; |
| 51 |
} |
| 52 |
} |
| 53 |
|