'; if ( $show_brand ) { woocommerce_wp_text_input( array( 'id' => '_prodlyra_brand', 'label' => __( 'Brand', 'prodlyra' ), 'desc_tip' => true, 'description' => __( 'AI shopping assistants show and filter products by brand. If you make the product yourself, use your store name.', 'prodlyra' ), ) ); } if ( $show_gtin ) { woocommerce_wp_text_input( array( 'id' => '_prodlyra_gtin', 'label' => __( 'GTIN / EAN / UPC', 'prodlyra' ), 'desc_tip' => true, 'description' => __( 'The barcode number (8, 12, 13 or 14 digits). Leave empty if the product has none.', 'prodlyra' ), ) ); } echo ''; } /** * Saves the fields with the product. * * @param WC_Product $product Product being saved. */ public static function save( $product ) { // WooCommerce prints this nonce on the product form. if ( ! isset( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['woocommerce_meta_nonce'] ) ), 'woocommerce_save_data' ) ) { return; } if ( ! current_user_can( 'edit_product', $product->get_id() ) ) { return; } if ( isset( $_POST['_prodlyra_brand'] ) ) { $brand = sanitize_text_field( wp_unslash( $_POST['_prodlyra_brand'] ) ); if ( '' === $brand ) { $product->delete_meta_data( '_prodlyra_brand' ); } else { $product->update_meta_data( '_prodlyra_brand', $brand ); } } if ( isset( $_POST['_prodlyra_gtin'] ) ) { $gtin = preg_replace( '/\D/', '', sanitize_text_field( wp_unslash( $_POST['_prodlyra_gtin'] ) ) ); if ( '' === $gtin ) { $product->delete_meta_data( '_prodlyra_gtin' ); } else { $product->update_meta_data( '_prodlyra_gtin', $gtin ); } } } }