• hello,

    it’d be just great if you could make your plugin WPML compatible, at the moment related products in admin on a translated product are picked from those in the original language, and they don’t show up in front end.

Viewing 1 replies (of 1 total)
  • Hi,

    This is David from the WPML compatibility team. We recently had a bug report in our forum about using Custom Related Products together with WPML.

    We put together a small snippet that translates the related product ids on the fly to make it work:

    add_action( 'init', 'wcrp_wpml_loaded' );
    function wcrp_wpml_loaded() {
    	if ( apply_filters( 'wpml_setting', false, 'setup_complete' ) ) {
    		add_filter( 'get_post_metadata', 'wcrp_translate_related_ids', 10, 4 );
    	}
    }
    function wcrp_translate_related_ids( $value, $post_id, $meta_key, $single ) {
    	global $wpdb;
    
    	if ( '_wcrp_related_ids' === $meta_key ) {
    		$ids = maybe_unserialize( $wpdb->get_var( $wpdb->prepare(
    			"SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s",
    			$post_id,
    			$meta_key
    		) ) );
    		$value = array();
    		foreach ( $ids as $id ) {
    			$value[] = apply_filters( 'wpml_object_id', $id, get_post_type( $id ), true );
    		}
    		$value = array( $value );
    	}
    
    	return $value;
    }

    If you have a child theme, you can place this code in functions.php in the child theme. This is the quickest way.

    But ideally, the plugin author can include it directly in the plugin.

    Best
    David

Viewing 1 replies (of 1 total)
  • The topic ‘WPML compatibility’ is closed to new replies.