Merge pull request #21305 from woocommerce/fix/product-review-type
Save comment_type for product reviews
This commit is contained in:
commit
14aea98d49
|
@ -48,6 +48,9 @@ class WC_Comments {
|
|||
|
||||
// Review of verified purchase.
|
||||
add_action( 'comment_post', array( __CLASS__, 'add_comment_purchase_verification' ) );
|
||||
|
||||
// Set comment type.
|
||||
add_action( 'preprocess_comment', array( __CLASS__, 'update_comment_type' ), 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -405,6 +408,21 @@ class WC_Comments {
|
|||
|
||||
return $counts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update comment type of product reviews.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @param array $comment_data Comment data.
|
||||
* @return array
|
||||
*/
|
||||
public static function update_comment_type( $comment_data ) {
|
||||
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $comment_data['comment_type'] ) && '' === $comment_data['comment_type'] && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) ) { // WPCS: input var ok, CSRF ok.
|
||||
$comment_data['comment_type'] = 'review';
|
||||
}
|
||||
|
||||
return $comment_data;
|
||||
}
|
||||
}
|
||||
|
||||
WC_Comments::init();
|
||||
|
|
|
@ -115,6 +115,7 @@ class WC_Install {
|
|||
),
|
||||
'3.5.0' => array(
|
||||
'wc_update_350_order_customer_id',
|
||||
'wc_update_350_reviews_comment_type',
|
||||
'wc_update_350_change_woocommerce_sessions_schema',
|
||||
'wc_update_350_db_version',
|
||||
),
|
||||
|
|
|
@ -1975,6 +1975,17 @@ function wc_update_350_order_customer_id( $updater = false ) {
|
|||
wp_cache_flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment type to 'review' for product reviews that don't have a comment type.
|
||||
*/
|
||||
function wc_update_350_reviews_comment_type() {
|
||||
global $wpdb;
|
||||
|
||||
$wpdb->query(
|
||||
"UPDATE {$wpdb->prefix}comments JOIN {$wpdb->prefix}posts ON {$wpdb->prefix}posts.ID = {$wpdb->prefix}comments.comment_post_ID AND ( {$wpdb->prefix}posts.post_type = 'product' OR {$wpdb->prefix}posts.post_type = 'product_variation' ) SET {$wpdb->prefix}comments.comment_type = 'review' WHERE {$wpdb->prefix}comments.comment_type = ''"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change wp_woocommerce_sessions schema to use a bigint auto increment field
|
||||
* instead of char(32) field as the primary key. Doing this change primarily as
|
||||
|
|
Loading…
Reference in New Issue