<?php
/**
 * Update product description from my.meteosales
 *
 * @link       info@meteosales.com
 * @since      1.0.2
 *
 * @package    Meteosales
 * @subpackage Meteosales/includes
 */
if ( ! defined( 'ABSPATH' ) ) exit;
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {//if woocommerce is activated
   
    add_action( 'wp_footer', 'meteosales_ms_update_product_description' ,200);
    function meteosales_ms_update_product_description() {
        
        if(isset($_POST['update_description']) && $_POST['update_description'] != ""){ 
            global  $woocommerce;
            $ms_product_id = $_POST['ms_product_id'];
            echo "$ms_product_id <br>";
            $post = get_post( $ms_product_id );
            if($post != null){
                $ms_product_description = $_POST['ms_product_description'];
                $post->post_content = stripcslashes($ms_product_description);
                wp_update_post( $post );
                echo "ok";
            }
            else{
                echo "product not found";
            }

        }
    } 
    
    function meteosales_ms_add_cors_http_header(){
        header("Access-Control-Allow-Origin: https://my.meteosales.com");
    }
    add_action('init','meteosales_ms_add_cors_http_header');
    
}