WC_AJAX::get_variation
Get a matching variation based on posted attributes.
Method of the class: WC_AJAX{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WC_AJAX::get_variation();
WC_AJAX::get_variation() WC AJAX::get variation code WC 10.8.1
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
}