2017-09-29 5 views
0

Ich versuche, Produktkommentare manuell aus der Datenbank zu schreiben.Wordpress/Woocommerce Kommentar vom Code

$wpdb->insert($table, 
     array(
       "comment_post_ID"  => '26475', 
       "comment_author"  => 'text', 
       "comment_author_email" => "[email protected]", 
       "comment_author_IP"  => "192.168.122.122", 
       "comment_date"   => "2017-09-28 14:53:46", 
       "comment_date_gmt"  => "2017-09-28 10:53:46", 
       "comment_content"  => "Testing Product", 
       "comment_karma"   => "0", 
       "comment_approved"  => "1", 
       "comment_agent"   => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36", 
       "comment_parent"  => "0", 
       "user_id"    => "0", 
)); 

$ListingID = $wpdb->get_var("SELECT comment_ID FROM ". $table ." WHERE comment_post_ID = '26475' AND comment_content = 'Very Good Product'"); 

     $wpdb->insert($table_comment_meta, 
     array(
       "comment_id" => $ListingID, 
       "meta_key" => "verified", 
       "meta_value" => "0", 

      )); 


     // $wpdb->insert($table_comment_meta, 
     array(
       "comment_id" => $ListingID, 
       "meta_key" => "rating", 
       "meta_value" => "5", 

      )); 

Nachdem ich führen Sie den Code, und gehen Sie auf der Produktseite, den Kommentar und die Bewertung erscheint, aber das Problem, dass ich habe, wo es Bewertungen gezählt bevor sie angezeigt werden, dosen't es diesen Kommentar zählen .

Jemand hat eine Idee, was ich hier vermisse.

Antwort

0

können Sie diese versuchen

<?php 

$time = current_time('mysql'); 

$data = array(
    'comment_post_ID' => 1, 
    'comment_author' => 'admin', 
    'comment_author_email' => '[email protected]', 
    'comment_author_url' => 'http://', 
    'comment_content' => 'content here', 
    'comment_type' => '', 
    'comment_parent' => 0, 
    'user_id' => 1, 
    'comment_author_IP' => '127.0.0.1', 
    'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)', 
    'comment_date' => $time, 
    'comment_approved' => 1, 
); 

wp_insert_comment($data); 

?> 

Hope this helfen.

+0

Danke, es funktioniert, und ich fand einen anderen Weg. Ändern Sie den Wert von table_comment_meta mit diesem \t add_comment_meta ($ ListingID, 'rating', '5', true); \t wp_update_comment (array ("comment_ID" => $ ListingID, "comment_approved" => 1)); –

Verwandte Themen