<?php

/**
 * Polylang Integration Handler
 * 
 * @package cwpt
 * @since 1.0.0
 */

defined('ABSPATH') or die;

class CWPT_Polylang
{
    /**
     * Disable Polylang meta syncing for custom product types
     * 
     * @param array $metas
     * @param int $from
     * @param int $to
     * @return array
     */
    public static function disable_meta_sync($metas, $from, $to)
    {
        $excluded_product_types = CWPT_Settings::get('name_ids');

        $from_product_type = get_post_meta($from, '_product_type', true);
        $to_product_type = get_post_meta($to, '_product_type', true);

        if (in_array($from_product_type, $excluded_product_types) || in_array($to_product_type, $excluded_product_types)) {
            unset($metas['_product_type']);
            return $metas;
        }

        return $metas;
    }

    /**
     * Add custom product type to Polylang post types
     * 
     * @param array $post_types
     * @param bool $is_settings
     * @return array
     */
    public static function add_to_post_types($post_types, $is_settings)
    {
        $post_types['custom-product-type'] = 'custom-product-type';
        return $post_types;
    }
}
