WordPress at Your Fingertips
function is not described

WC_AJAX::get_variation() public WC 1.0

Get a matching variation based on posted attributes.

{} It's a method of the class: WC_AJAX{}

No Hooks.

Return

null. Nothing.

Usage

$result = WC_AJAX::get_variation();

Code of WC_AJAX::get_variation() WC 5.9.0

public static function get_variation() {
	ob_start();

	// phpcs:disable WordPress.Security.NonceVerification.Missing
	if ( empty( $_POST['product_id'] ) ) {
		wp_die();
	}

	$variable_product = wc_get_product( absint( $_POST['product_id'] ) );

	if ( ! $variable_product ) {
		wp_die();
	}

	$data_store   = WC_Data_Store::load( 'product' );
	$variation_id = $data_store->find_matching_product_variation( $variable_product, wp_unslash( $_POST ) );
	$variation    = $variation_id ? $variable_product->get_available_variation( $variation_id ) : false;
	wp_send_json( $variation );
	// phpcs:enable
}