0
也許有人能夠幫助我。我想將產品屬性網址從pa_更改爲其他內容。 (例如http://website.com/?pa_color=black爲?product_color = black。)自定義產品屬性網址
任何解決方案的傢伙?
問候
也許有人能夠幫助我。我想將產品屬性網址從pa_更改爲其他內容。 (例如http://website.com/?pa_color=black爲?product_color = black。)自定義產品屬性網址
任何解決方案的傢伙?
問候
,使您可以在您的網址和產品屬性使用自定義的基礎,而不是PA_的功能將不再與WooCommerce標準。
您必須首先確保您已將您的分類標準永久鏈接設置爲您希望產品網址的基礎。如果您進入WordPress儀表板>設置>永久性菜單,則可以將類別,術語和屬性更改爲對您的產品最有意義的內容。通過改變這些偏好,你可以在你的產品上使用自定義的基礎(不要在分類中重複基礎,這會產生衝突)。
然後,您將需要將以下代碼添加到主題functions.php文件:
// Change attribute rewrite rules
add_action('woocommerce_register_taxonomy', 'razorfrog_woo_register_taxonomy');
function razorfrog_woo_register_taxonomy() {
global $razorfrog_woo_attribute_labels;
$razorfrog_woo_attributes_labels = array();
if ($attribute_taxonomies = wc_get_attribute_taxonomies()) {
foreach ($attribute_taxonomies as $tax) {
if ($name = wc_attribute_taxonomy_name($tax->attribute_name)) {
$razorfrog_woo_attribute_labels[ $tax->attribute_label ] = $tax->attribute_name;
add_filter('woocommerce_taxonomy_args_'.$name, 'razorfrog_woo_taxonomy_args');
}
}
}
}
function razorfrog_woo_taxonomy_args($taxonomy_data) {
global $razorfrog_woo_attribute_labels;
if (isset($taxonomy_data['rewrite']) && is_array($taxonomy_data['rewrite']) && empty($taxonomy_data['rewrite']['slug'])) {
$taxonomy_data['rewrite']['slug'] = $razorfrog_woo_attribute_labels[ $taxonomy_data['labels']['name'] ];
}
return $taxonomy_data;
}
希望這有助於!
有什麼方法可以編輯一些woocommerce文件來改變屬性的pa_?我想把它加入我的小孩主題。 –
對不起,喬治!我意識到,自從WooCommerce的2.3版本以來,您不能只在分類偏好中編輯基礎。我在你的子主題中添加了你需要添加到你的functions.php文件中的代碼。希望工程! –
此代碼正在刪除pa_? –