我有一些属性具有相同的显示名称,但唯一的蛞蝓。当创造新的可变产品时,不可能区分两者之间的区别。有没有可能在“添加”属性中包含slug?Screenshot
4dbbbstv1#
我有同样的需求,不知何故,我可以通过使用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 );
Screenshot
1条答案
按热度按时间4dbbbstv1#
我有同样的需求,不知何故,我可以通过使用PHP + jQuery来实现它:
将以下内容添加到主题functions.php文件中:
然后在your-theme > assets > js文件夹中创建一个名为show_slugs. js的文件,内容如下:
Screenshot