WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_REST_Product_Variations_V2_Controller::delete_item() public WC 1.0

Delete a variation.

{} Это метод класса: WC_REST_Product_Variations_V2_Controller{}

Возвращает

true/false/WP_Error/WP_REST_Response.

Использование

$WC_REST_Product_Variations_V2_Controller = new WC_REST_Product_Variations_V2_Controller();
$WC_REST_Product_Variations_V2_Controller->delete_item( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Код WC_REST_Product_Variations_V2_Controller::delete_item() WC 4.7.0

<?php
public function delete_item( $request ) {
	$force  = (bool) $request['force'];
	$object = $this->get_object( (int) $request['id'] );
	$result = false;

	if ( ! $object || 0 === $object->get_id() ) {
		return new WP_Error(
			"woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array(
				'status' => 404,
			)
		);
	}

	$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) );

	/**
	 * Filter whether an object is trashable.
	 *
	 * Return false to disable trash support for the object.
	 *
	 * @param boolean $supports_trash Whether the object type support trashing.
	 * @param WC_Data $object         The object being considered for trashing support.
	 */
	$supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object );

	if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
		return new WP_Error(
			/* translators: %s: post type */
			"woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array(
				'status' => rest_authorization_required_code(),
			)
		);
	}

	$request->set_param( 'context', 'edit' );
	$response = $this->prepare_object_for_response( $object, $request );

	// If we're forcing, then delete permanently.
	if ( $force ) {
		$object->delete( true );
		$result = 0 === $object->get_id();
	} else {
		// If we don't support trashing for this type, error out.
		if ( ! $supports_trash ) {
			return new WP_Error(
				/* translators: %s: post type */
				'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array(
					'status' => 501,
				)
			);
		}

		// Otherwise, only trash if we haven't already.
		if ( is_callable( array( $object, 'get_status' ) ) ) {
			if ( 'trash' === $object->get_status() ) {
				return new WP_Error(
					/* translators: %s: post type */
					'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array(
						'status' => 410,
					)
				);
			}

			$object->delete();
			$result = 'trash' === $object->get_status();
		}
	}

	if ( ! $result ) {
		return new WP_Error(
			/* translators: %s: post type */
			'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array(
				'status' => 500,
			)
		);
	}

	// Delete parent product transients.
	if ( 0 !== $object->get_parent_id() ) {
		wc_delete_product_transients( $object->get_parent_id() );
	}

	/**
	 * Fires after a single object is deleted or trashed via the REST API.
	 *
	 * @param WC_Data          $object   The deleted or trashed object.
	 * @param WP_REST_Response $response The response data.
	 * @param WP_REST_Request  $request  The request sent to the API.
	 */
	do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );

	return $response;
}