WC_AJAX::get_variation
Get a matching variation based on posted attributes.
Метод класса: WC_AJAX{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
$result = WC_AJAX::get_variation();
Код WC_AJAX::get_variation() WC AJAX::get variation WC 11.3.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();
}
if ( ! $variable_product->is_viewable() ) {
wp_die();
}
// Match the product page, which shows variation details only after the product password is entered.
if ( post_password_required( $variable_product->get_id() ) ) {
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
}