我有同样的需求,不知何故我可以通过使用 PHP + jQuery 来实现它:
将以下内容添加到您的主题functions.php文件中:
// Show attribute label + slugs in wordpress admin product editing pages.
function show_attribute_slugs_in_product_edit_page( $hook ) {
global $post;
if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
if ( 'product' === $post->post_type ) {
wp_enqueue_script( 'show_slugs', get_stylesheet_directory_uri().'/assets/js/show_slugs.js' );
}
}
}
add_action( 'admin_enqueue_scripts', 'show_attribute_slugs_in_product_edit_page', 10, 1 );
并在 your-theme > assets > js 文件夹中创建一个名为 show_slugs.js 的文件,其中包含以下内容:
(function( $ ){
var attr_renamed = false;
$(document).on('click', '#woocommerce-product-data > div.inside > div > ul > li.attribute_tab > a', function(){
if (attr_renamed === false) {
$("#product_attributes > div.toolbar.toolbar-top > select option").not(":nth-child(1)").each(function() {
var attr_label = $(this).text();
var attr_value = $(this).val().replace('pa_', '');
$(this).text(attr_label + ' (' + attr_value + ')');
attr_renamed = true;
});
}
});
})( jQuery );
我有同样的问题。我需要在下拉列表中显示值。我将您的代码添加到我的网站,但它对属性不起作用。检查了一些东西,但我无法修复它。