<?php

namespace StoreEngine\Addons\Paddle;

use StoreEngine\Classes\Order\OrderItemProduct;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Hooks {

	public static function init() {
		add_action( 'storeengine/checkout/create_order_line_item', [ __CLASS__, 'save_order_item_meta' ] );
	}

	public static function save_order_item_meta( OrderItemProduct $item ) {
		$product_tax_category = get_post_meta( $item->get_product_id(), '_storeengine_paddle_tax_category', true );
		if ( empty( $product_tax_category ) ) {
			return;
		}

		$item->add_meta_data( '_paddle_tax_category', $product_tax_category );
	}

}
