/** * romclassic: Auto-Publish WooCommerce Products * * როდესაც პროდუქტი draft-ში ხდება შენახული, მაგრამ აქვს რეალური მონაცემები * (სახელი ან ფოტო), ავტომატურად გაქვეყნდება. */ // ============= ფენა 1: POST data filter (ადრეულ ეტაპზე) ============= add_filter( 'wp_insert_post_data', function ( $data, $postarr ) { // მხოლოდ პროდუქტებისთვის if ( empty( $data['post_type'] ) || 'product' !== $data['post_type'] ) { return $data; } // ავტომატური შენახვა და რევიზიები არ შევეხოთ if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $postarr['ID'] ?? 0 ) ) { return $data; } // მხოლოდ publish-ის უფლების მქონე მომხმარებლები if ( ! current_user_can( 'publish_products' ) ) { return $data; } // auto-draft (WP-ის შიდა) და ცარიელი ფორმის შენახვას არ შევეხოთ $title = trim( $data['post_title'] ?? '' ); if ( empty( $title ) || 'AUTO-DRAFT' === strtoupper( $title ) ) { return $data; } // draft/pending/auto-draft → publish if ( in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ), true ) ) { $data['post_status'] = 'publish'; // თარიღი დავაფიქსიროთ (თუ მომავალში არ არის) if ( empty( $data['post_date_gmt'] ) || '0000-00-00 00:00:00' === $data['post_date_gmt'] ) { $data['post_date'] = current_time( 'mysql' ); $data['post_date_gmt'] = current_time( 'mysql', 1 ); } } return $data; }, 99, 2 ); // ============= ფენა 2: Fallback — save_post-ის შემდეგ გადაამოწმე ============= add_action( 'save_post_product', function ( $post_id, $post, $update ) { // autosave/revision bypass if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( wp_is_post_revision( $post_id ) ) { return; } if ( ! current_user_can( 'publish_products' ) ) { return; } // თუ არ არის draft, არაფერი არ შეცვალო if ( ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ), true ) ) { return; } // ცარიელი პროდუქტი (ოპერატორმა ახლახან ღილაკი "ახალი" დააჭირა) ნუ გამოქვეყნდება $title = trim( $post->post_title ); $thumb_id = (int) get_post_thumbnail_id( $post_id ); $has_price = get_post_meta( $post_id, '_regular_price', true ) !== ''; if ( empty( $title ) || 'AUTO-DRAFT' === strtoupper( $title ) ) { return; } // საკმარისი მონაცემები აქვს → publish if ( $title && ( $thumb_id || $has_price ) ) { remove_action( 'save_post_product', __FUNCTION__, 10 ); wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish', ) ); } }, 10, 3 ); Furniture House | Italian Furniture Showroom • Romclassic

Catalogue