2017-04-17 266 views
0

我在WordPress的使用WooCommerce並增加了產品&產品類別的WooCommerce-如何從網站中刪除產品和產品類別?

網址。

http://dev.unwaveringmedia.com/8dim/product-category/all-party-supplies/http://dev.unwaveringmedia.com/8dim/product/14-snowman-serving-tray/

我需要從網址中刪除 '產品' & '產品類別'。有沒有辦法修改永久鏈接並刪除它們?

+0

你有沒有ked設置 - >固定鏈接? –

+0

@Bhagya Shree不推薦,閱讀此https://docs.woocommerce.com/document/removing-product-product-category-or-shop-from-the-urls/ – kebir

回答

1

是的。但是,請閱讀這篇文章第一https://docs.woocommerce.com/document/removing-product-product-category-or-shop-from-the-urls/

您可以通過更改此:

  1. 您可以更改產品類別基地設置固定鏈接>永久鏈接>可選>產品類別基地= ./(型./ )。

  2. 確保您沒有任何頁面,張貼或附件與分類頁面具有相同的名稱(slug),否則它們會發生碰撞,代碼將無法工作。

  3. 安裝並激活下面的插件: (欲瞭解更多信息,請參閱https://timersys.com/remove-product-category-slug-woocommerce/

`

<?php 
/* 
Plugin Name: Remove product-category slug 
Plugin URI: https://timersys.com/ 
Description: Check if url slug matches a woocommerce product category and use it instead 
Version: 0.1 
Author: Timersys 
License: GPLv2 or later 
*/ 
add_filter('request', function($vars) { 
    global $wpdb; 
    if(! empty($vars['pagename']) || ! empty($vars['category_name']) || ! empty($vars['name']) || ! empty($vars['attachment'])) { 
     $slug = ! empty($vars['pagename']) ? $vars['pagename'] : (! empty($vars['name']) ? $vars['name'] : (!empty($vars['category_name']) ? $vars['category_name'] : $vars['attachment'])); 
     $exists = $wpdb->get_var($wpdb->prepare("SELECT t.term_id FROM $wpdb->terms t LEFT JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id WHERE tt.taxonomy = 'product_cat' AND t.slug = %s" ,array($slug))); 
     if($exists){ 
      $old_vars = $vars; 
      $vars = array('product_cat' => $slug); 
      if (!empty($old_vars['paged']) || !empty($old_vars['page'])) 
       $vars['paged'] = ! empty($old_vars['paged']) ? $old_vars['paged'] : $old_vars['page']; 
      if (!empty($old_vars['orderby'])) 
        $vars['orderby'] = $old_vars['orderby']; 
       if (!empty($old_vars['order'])) 
        $vars['order'] = $old_vars['order'];  
     } 
    } 
    return $vars; 
});` 

enter image description here

欲瞭解更多信息,請參閱https://timersys.com/remove-product-category-slug-woocommerce/

+0

爲我工作最新的Woocommerce 3.3.3 。謝謝 –

相關問題