Channel_Sync::post_deleted( int $post_id )
Summary
When a post is deleted, permanently mark it deleted in the channel
Parameters
- $post_id
-
(int) (Required)
Return
(void)
Source
File: src/BigCommerce/Post_Types/Product/Channel_Sync.php
public function post_deleted( $post_id ) { if ( Product::NAME !== get_post_type( $post_id ) ) { return; } /** * Filter whether deleting the post should be pushed up to the * BigCommerce channel listing. * * @param bool $update Whether the update should be pushed * @param int $post_id The ID of the post being updated */ if ( ! apply_filters( 'bigcommerce/channel/listing/should_delete', true, $post_id ) ) { return; } $product = new Product( $post_id ); $channel_id = $product->get_channel_id(); $listing_id = $product->get_listing_id(); if ( empty( $channel_id ) || empty( $listing_id ) ) { return; } try { $response = $this->channels->getChannelListing( $channel_id, $listing_id ); $listing = $response->getData(); } catch ( ApiException $e ) { /** * Error triggered when fetching a listing fails * * @param int $channel_id * @param int $listing_id * @param ApiException $e */ do_action( 'bigcommerce/channel/error/could_not_fetch_listing', $channel_id, $listing_id, $e ); return; } $update_request = new UpdateListingRequest( [ 'channel_id' => $channel_id, 'listing_id' => $listing_id, 'product_id' => $listing->getProductId(), 'state' => 'deleted', 'name' => $listing->getName(), 'description' => $listing->getDescription(), 'external_id' => $listing->getExternalId(), 'variants' => $listing->getVariants(), ] ); try { $this->channels->updateChannelListings( $channel_id, [ $update_request ] ); } catch ( ApiException $e ) { /** * Error triggered when updating a listing fails * * @param int $channel_id * @param int $listing_id * @param ApiException $e */ do_action( 'bigcommerce/channel/error/could_not_update_listing', $channel_id, $listing_id, $e ); return; } }