wpuxsolutions

WooCommerce Product Attributes

Apr 8th, 2021 (edited)
129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * add to functions.php of your theme
  3.  * works for WooCommerce product attributes assigned to media library only
  4.  */
  5.  
  6. add_action( 'wp_loaded', 'YOUR_PREFIX_on_wp_loaded' );
  7.  
  8. function YOUR_PREFIX_on_wp_loaded() {
  9.    
  10.    global $wp_taxonomies,
  11.           $pagenow;
  12.  
  13.    if ( ! ( 'post.php' === $pagenow && isset($_GET['post'] ) && 'product' === get_post_type( $_GET['post'] ) ) ) {
  14.    
  15.         foreach ( get_object_taxonomies('attachment','object') as $taxonomy => $params ) {
  16.  
  17.             if ( in_array('attachment',$params->object_type) &&
  18.                  in_array('product',$params->object_type) ) {
  19.                      
  20.                 $wp_taxonomies[$taxonomy]->show_ui = 1;
  21.                 $wp_taxonomies[$taxonomy]->public = 1;
  22.  
  23.                 if ( empty( $wp_taxonomies[$taxonomy]->meta_box_cb ) ) {
  24.                     $wp_taxonomies[$taxonomy]->meta_box_cb = 'post_tags_meta_box';
  25.                 }
  26.             }
  27.         }
  28.     }
  29. }
RAW Paste Data