Cho mình hỏi làm sao để xóa cái Slug đường dẫn Product (chi tiết sản phẩm), Product-category (chuyên mục sản phẩm) của plugin Woocommerce như thế nào vậy. VD: hiện tại web của mình Chuyên mục sản phẩm nó hiện là: domain-com/chuyen-mục-san-pham/thuoc-cung-duong -> (muốn chuyển thành) domain-com/thuoc-cung-duong. Chuyên mục sản phẩm nó hiện là: domain-com/chi-tiet-san-pham/durex -> (muốn chuyển thành) domain-com/durex. Mình muốn nó xóa cái slug product-cat (product-category), product ở chi tiết sản phẩm thì làm sao giúp mình với. Chỉ rõ giúp mình với. Cảm ơn
Của bạn đây nhé (tham khảo ở stackexchange và levantoan) áp dụng chạy thật 100% tốt: Bước 1: truy cập vào tập tin function.php của themes mở file lên, sau đó chèn code sau vào. PHP: /** Code Bỏ /product/ hoặc /san-pham/ hoặc /shop/ ... có hỗ trợ dạng %product_cat%* Thay /san-pham/ bằng slug hiện tại của bạn*/function devvn_remove_slug( $post_link, $post ) { if ( !in_array( get_post_type($post), array( 'product' ) ) || 'publish' != $post->post_status ) { return $post_link; } if('product' == $post->post_type){ $post_link = str_replace( '/san-pham/', '/', $post_link ); //Thay san-pham bằng slug hiện tại của bạn }else{ $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); } return $post_link;}add_filter( 'post_type_link', 'devvn_remove_slug', 10, 2 );/*Sửa lỗi 404 sau khi đã remove slug product hoặc san-pham*/function devvn_woo_product_rewrite_rules($flash = false) { global $wp_post_types, $wpdb; $siteLink = esc_url(home_url('/')); foreach ($wp_post_types as $type=>$custom_post) { if($type == 'product'){ if ($custom_post->_builtin == false) { $querystr = "SELECT {$wpdb->posts}.post_name, {$wpdb->posts}.ID FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_status = 'publish' AND {$wpdb->posts}.post_type = '{$type}'"; $posts = $wpdb->get_results($querystr, OBJECT); foreach ($posts as $post) { $current_slug = get_permalink($post->ID); $base_product = str_replace($siteLink,'',$current_slug); add_rewrite_rule($base_product.'?$', "index.php?{$custom_post->query_var}={$post->post_name}", 'top'); add_rewrite_rule($base_product.'comment-page-([0-9]{1,})/?$', 'index.php?'.$custom_post->query_var.'='.$post->post_name.'&cpage=$matches[1]', 'top'); add_rewrite_rule($base_product.'(?:feed/)?(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$custom_post->query_var.'='.$post->post_name.'&feed=$matches[1]','top'); } } } } if ($flash == true) flush_rewrite_rules(false);}add_action('init', 'devvn_woo_product_rewrite_rules');/*Fix lỗi khi tạo sản phẩm mới bị 404*/function devvn_woo_new_product_post_save($post_id){ global $wp_post_types; $post_type = get_post_type($post_id); foreach ($wp_post_types as $type=>$custom_post) { if ($custom_post->_builtin == false && $type == $post_type) { devvn_woo_product_rewrite_rules(true); } }}add_action('wp_insert_post', 'devvn_woo_new_product_post_save');//xoa chuyen muc san pham di /san-pham/thuoc-abc category thanh /thuoc-abcadd_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;}); Bước 2: cấu hình lại url permalink của web như hình sau: Cài đặt -> Đường dẫn tĩnh