Viewing 1 replies (of 1 total)
  • Plugin Author ndre

    (@ndre)

    Hello @rneo83,

    You can use the following code to set the default product category:

    add_action( 'product_edit_save', 'my_default_product_category' );
    
    function my_default_product_category( $post ) {
       if ( 'publish' === $post->post_status ) {
          $default_category = 'my-default-category-slug';
          $terms = wp_get_post_terms( $post->ID, 'al_product-cat' );
          if ( empty( $terms ) ) {
             wp_set_object_terms( $post->ID, $default_category, 'al_product-cat' );
          }
       }
    }

    You should replace my-default-category-slug with your selected category slug.

Viewing 1 replies (of 1 total)
  • The topic ‘Default Category’ is closed to new replies.