• Hey,

    It seems the sync translation doesn’t work while you are updating a product through wp cli, for support it, please make below changes:

    1. classes/class-woocommerce-wpml.php L199

    
    if ( is_admin() || wpml_is_rest_request() ) {
    
    }
    

    Should changed to:

    
    if (is_admin() || wpml_is_rest_request() || defined('WP_CLI')) {
    
    }
    

    2. Add a new method in class woocommerce_wpml

    
    public function get_sync_object()
    {
        return $this->sync_product_data;
    }
    

    3. inc/translation-editor/class-wcml-synchronize-product-data.php L95

    
    $trashing   = isset( $_GET['action'] ) && 'trash' === $_GET['action'];
    if (
    	$post_type !== 'product' ||
    	empty( $original_product_id ) ||
    	isset( $_POST['autosave'] ) ||
    	( $pagenow !== 'post.php' && $pagenow !== 'post-new.php' && $pagenow !== 'admin.php' && ! $ajax_call && ! $api_call ) ||
    	$trashing ||
    	$auto_draft
    ) {
    	return;
    }
    

    Should changed to:

    
    $trashing   = isset( $_GET['action'] ) && 'trash' === $_GET['action'];
    if (
            !defined('WP_CLI') and
    	$post_type !== 'product' ||
    	empty( $original_product_id ) ||
    	isset( $_POST['autosave'] ) ||
    	( $pagenow !== 'post.php' && $pagenow !== 'post-new.php' && $pagenow !== 'admin.php' && ! $ajax_call && ! $api_call ) ||
    	$trashing ||
    	$auto_draft
    ) {
    	return;
    }
    

    If you have a git repository for your plugin, then let me know, I’ll send a pull request.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello Mostafa,
    Thanks for your contribution!

    I’ll create a ticket in our queue to review and include your changes ( we don’t have public repo yet ).

    Can you please also provide commands which you’re using for updating product so we can complete our testing with your case as well.

    Regards,

    Thread Starter Mostafa Soufi

    (@mostafas1990)

    The command is:

    wp wc product update <id>

    https://github.com/woocommerce/woocommerce/wiki/WC-CLI-Commands#wc-product-update-id

    Anyway with that method get_sync_object, we want to run the product sync manually something like:

    global $woocommerce_wpml;
    $post      = get_post($productId);
    $woocommerce_wpml->getSyncObject()->synchronize_products($post->ID, $post);

    Hello Mostafa,
    thanks for the details!

    I’ll update you here when will know a version number where it will be included.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Compatible sync translation with wp cli’ is closed to new replies.