WC_Post_Data::trash_post
Trash post.
Method of the class: WC_Post_Data{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WC_Post_Data::trash_post( $id );
- $id(mixed) (required)
- Post ID.
WC_Post_Data::trash_post() WC Post Data::trash post code WC 10.7.0
public static function trash_post( $id ) {
if ( ! $id ) {
return;
}
$post_type = self::get_post_type( $id );
// If this is an order, trash any refunds too.
if ( in_array( $post_type, wc_get_order_types( 'order-count' ), true ) ) {
global $wpdb;
$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );
foreach ( $refunds as $refund ) {
$wpdb->update( $wpdb->posts, array( 'post_status' => OrderStatus::TRASH ), array( 'ID' => $refund->ID ) );
}
wc_delete_shop_order_transients( $id );
// If this is a product, trash children variations.
} elseif ( 'product' === $post_type ) {
$data_store = WC_Data_Store::load( 'product-variable' );
$data_store->delete_variations( $id, false );
wc_get_container()->get( ProductAttributesLookupDataStore::class )->on_product_deleted( $id );
} elseif ( 'product_variation' === $post_type ) {
wc_get_container()->get( ProductAttributesLookupDataStore::class )->on_product_deleted( $id );
}
}