Support » Plugin: MultilingualPress » WooCommerce Shop Pages not Linked

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author dinamiko

    (@dinamiko)

    Hi WP Channel,

    You need to add mlp_linked_element_link filter to your theme functions.php and adapt $fragments array based on your site IDs, in this example there are two sites, English with ID 1 and Spanish with id 2:

    function filter_mlp_linked_cpt_archive_link(
    	$url,
    	$target_site_id,
    	$target_content_id,
    	Mlp_Translation_Interface $translation
    ) {
    
    	if ( ! is_singular( 'product' ) && ! is_post_type_archive() && ! is_archive() ) {
    		return $url;
    	}
    
    	if ( ! is_a( $translation, 'Mlp_Translation_Interface' ) ) {
    		return $url;
    	}
    
    	$source_site_id = $translation->get_source_site_id();
    	if ( ! $source_site_id ) {
    		return $url;
    	}
    
    	if( is_singular( 'product' ) || is_post_type_archive() ) {
    
    		$fragments = array(
    			1 => array(
    				'/shop/',
    			),
    			2 => array(
    				'/tienda/',
    			)
    		);
    	}
    	else {
    
    		$fragments = array(
    			1 => array(
    				'/product-category/',
    			),
    			2 => array(
    				'/categoria-producto/',
    			)
    		);
    	}
    
    	if ( empty( $fragments[ $source_site_id ] ) ) {
    		return $url;
    	}
    
    	if ( empty( $fragments[ $target_site_id ] ) ) {
    		return $url;
    	}
    
    	return str_replace(
    		$fragments[ $source_site_id ],
    		$fragments[ $target_site_id ],
    		$url
    	);
    }
    
    add_filter( 'mlp_linked_element_link', 'filter_mlp_linked_cpt_archive_link', 10, 4 );

    Thanks,
    Emili

    Awesome it works!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WooCommerce Shop Pages not Linked’ is closed to new replies.