K
K
ko3a4ok2015-05-22 18:33:54
Link Shortening
ko3a4ok, 2015-05-22 18:33:54

How to make a direct link to a product in woocommerce?

Changing WooCommerce permalinks (remove shop) The
task is to remove /shop/ completely so that the link to any product is www.lala.com/product name/
advise who knows what.
maybe there is a plugin?
editing options-permalink.php or function.php ?
now the settings are /shop/%product_cat%
if you remove /shop/ then it automatically throws /product/%product_cat%
in general, you need to pick the code ... but where to dig?

oh yes, the search turned up this code:
remove_filter( 'post_type_link', 'woocommerce_product_cat_filter_post_link', 10, 2 ); // для версии woocommerce ниже 2.0 
remove_filter( 'post_type_link', 'woocommerce_product_post_type_link', 10, 2 ); // для версии woocommerce >= 2
add_filter( 'post_type_link', 'woocommerce_subcategory_permalink', 10, 2 );
function woocommerce_subcategory_permalink( $permalink, $post ) {

    // Прекращаем работу, если запись не является товаром
    if ( $post->post_type !== 'product' )
    	return $permalink;

    // Прекращаем работу, если тег перезаписи местоположения не находится в генерируемой ссылке
    if ( false === strpos( $permalink, '%product_cat%' ) )
    	return $permalink;

    // Получаем пользовательскую таксономию, используемую этой записью
    $terms = get_the_terms( $post->ID, 'product_cat' );

    if ( empty( $terms ) ) {
        $permalink = str_replace( '%product_cat%', _x('product', 'slug', 'woocommerce'), $permalink );
    } else {
        $first_term = array_shift( $terms );
        
        // Получаем иерархическую product_category
        $parents = woo_get_term_parents( $first_term->term_id, 'product_cat' );

        $permalink = str_replace( '%product_cat%/', $parents, $permalink );
    }

    return $permalink;
}

if ( ! function_exists( 'woo_get_term_parents' ) ) {
  function woo_get_term_parents( $id, $taxonomy ) {
    $chain = '';
    $parent = &get_term( $id, $taxonomy );
    if ( is_wp_error( $parent ) )
      	return $parent;
  
      $name = $parent->slug;
  
    if ( $parent->parent && ( $parent->parent != $parent->term_id )  ) {
        $chain .= woo_get_term_parents( $parent->parent, $taxonomy);
    }
  
      $chain .= $name."/";
      return $chain;
  } // End woo_get_term_parents()
}

only he does this from
/product/product_category/product_name
:
/product/catgory/sub_category/product_category/product_name
maybe there is something similar for my question.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Serdji, 2015-05-22
@ssumatokhin

Look for shortcodes for woocomerce. I’m sorry I can’t give a link, I don’t remember where I found it myself (. I found it, something like this [recent_products per_page="12 " columns="6"]

R
ryuuddo, 2015-07-09
@ryuuddo

and I have the opposite question - how to make the product attached to all the specified categories and subcategories?
this is what I mean:
/shop/category_name/subcategory_name/subsubcategory_name/product_name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question