WC_AJAX::feature_product()public staticWC 1.0

Toggle Featured status of a product from admin.

Method of the class: WC_AJAX{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_AJAX::feature_product();

WC_AJAX::feature_product() code WC 9.0.1

public static function feature_product() {
	if ( current_user_can( 'edit_products' ) && check_admin_referer( 'woocommerce-feature-product' ) && isset( $_GET['product_id'] ) ) {
		$product = wc_get_product( absint( $_GET['product_id'] ) );

		if ( $product ) {
			$product->set_featured( ! $product->get_featured() );
			$product->save();
		}
	}

	wp_safe_redirect( wp_get_referer() ? remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids' ), wp_get_referer() ) : admin_url( 'edit.php?post_type=product' ) );
	exit;
}