'text', 'label' => __('First Name', 'woocommerce'), 'placeholder' => __('', 'woocommerce'), 'required' => true, 'class' => array('form-row-wide'), 'priority' => 10, ); $fields['billing']['billing_last_name'] = array( 'type' => 'text', 'label' => __('Last Name', 'woocommerce'), 'placeholder' => __('', 'woocommerce'), 'required' => true, 'class' => array('form-row-wide'), 'priority' => 10, ); $fields['billing']['billing_email'] = array( 'type' => 'email', 'label' => __('E-mail', 'woocommerce'), 'placeholder' => __('', 'woocommerce'), 'required' => true, 'class' => array('form-row-wide'), 'priority' => 20, ); $fields['billing']['billing_phone'] = array( 'type' => 'tel', 'label' => __('Phone', 'woocommerce'), 'placeholder' => __('', 'woocommerce'), 'required' => true, 'class' => array('form-row-wide'), 'priority' => 30, ); // $fields['billing']['billing_state'] = array( // 'type' => 'text', // 'label' => __('Район/область', 'woocommerce'), // 'placeholder' => __('Район/область', 'woocommerce'), // 'required' => true, // 'class' => array('form-row-wide'), // 'priority' => 40, // ); $fields['billing']['billing_postcode'] = array( 'type' => 'text', 'label' => __('Postcode', 'woocommerce'), 'placeholder' => __('', 'woocommerce'), 'required' => false, 'class' => array('form-row-wide'), 'priority' => 40, ); $fields['billing']['billing_city'] = array( 'type' => 'text', 'label' => __('Town/City', 'woocommerce'), 'placeholder' => __('', 'woocommerce'), 'required' => true, 'class' => array('form-row-wide'), 'priority' => 40, ); // $fields['billing']['billing_address_1'] = array( // 'type' => 'text', // 'label' => __('House number and street name', 'woocommerce'), // 'placeholder' => __('House number and street name', 'woocommerce'), // 'required' => false, // 'class' => array('form-row-wide'), // 'priority' => 40, // ); // $fields['billing']['billing_address_2'] = array( // 'type' => 'text', // 'label' => __('Apartment, suite, unit, etc.', 'woocommerce'), // 'placeholder' => __('Apartment, suite, unit, etc.', 'woocommerce'), // 'required' => false, // 'class' => array('form-row-wide'), // 'priority' => 40, // ); return $fields; } // remove_action( 'woocommerce_review_order_before_payment', 'woocommerce_review_order_shipping' ); // add_action( 'init', function() { // update_option( 'woocommerce_enable_coupons', 'yes' ); // Включение купонов // } ); // add_action( 'wp_ajax_apply_coupon', 'custom_apply_coupon' ); // add_action( 'wp_ajax_nopriv_apply_coupon', 'custom_apply_coupon' ); // function custom_apply_coupon() { // $coupon_code = isset( $_POST['coupon_code'] ) ? sanitize_text_field( $_POST['coupon_code'] ) : ''; // if ( empty( $coupon_code ) ) { // wp_send_json_error( array( 'message' => 'Код купона не указан.' ) ); // } // // Применение купона // $applied = WC()->cart->apply_coupon( $coupon_code ); // if ( $applied ) { // wp_send_json_success(); // } else { // wp_send_json_error( array( 'message' => 'Купон не применён. Проверьте код.' ) ); // } // } add_filter( 'woocommerce_order_button_html', 'custom_checkout_button_classes' ); function custom_checkout_button_classes( $button ) { // Заменяем стандартные классы $button = '
'; return $button; } // /* // add_filter( 'woocommerce_checkout_fields', 'customize_checkout_registration_fields' ); // function customize_checkout_registration_fields( $fields ) { // // Убираем поле ввода пароля // unset( $fields['account']['account_password'] ); // return $fields; // } // */ // // Автоматическая генерация пароля // add_filter( 'woocommerce_checkout_posted_data', 'generate_password_for_registration' ); // function generate_password_for_registration( $data ) { // $billing_first_name = isset( $_POST['billing_first_name'] ) ? sanitize_text_field( $_POST['billing_first_name'] ) : ''; // $billing_last_name = isset( $_POST['billing_last_name'] ) ? sanitize_text_field( $_POST['billing_last_name'] ) : ''; // $billing_address_1 = isset( $_POST['billing_address_1'] ) ? sanitize_text_field( $_POST['billing_address_1'] ) : ''; // $billing_address_2 = isset( $_POST['billing_address_2'] ) ? sanitize_text_field( $_POST['billing_address_2'] ) : ''; // $billing_city = isset( $_POST['billing_city'] ) ? sanitize_text_field( $_POST['billing_city'] ) : ''; // $billing_postcode = isset( $_POST['billing_postcode'] ) ? sanitize_text_field( $_POST['billing_postcode'] ) : ''; // $billing_country = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; // $billing_state = isset( $_POST['billing_state'] ) ? sanitize_text_field( $_POST['billing_state'] ) : ''; // $billing_phone = isset( $_POST['billing_phone'] ) ? sanitize_text_field( $_POST['billing_phone'] ) : ''; // $billing_email = isset( $_POST['billing_email'] ) ? sanitize_email( $_POST['billing_email'] ) : ''; // $data['shipping_first_name'] = $data['billing_first_name']; // $data['shipping_last_name'] = $data['billing_last_name']; // $data['shipping_address_1'] = $data['billing_address_1'] . $data['billing_address_2']; // $data['shipping_city'] = $data['billing_city']; // $data['shipping_postcode'] = $data['billing_postcode']; // $data['shipping_country'] = $data['billing_country']; // $data['shipping_state'] = $data['billing_state']; // return $data; // } // function custom_register_user_from_post( $email, $pass ) { // // Проверяем, есть ли уже пользователь с таким email // if ( email_exists( $email ) ) { // return new WP_Error( 'email_exists', 'Этот email уже зарегистрирован.' ); // } // // Создаем пользователя в WordPress // $user_id = wp_create_user( $email, $pass, $email ); // if ( is_wp_error( $user_id ) ) { // return $user_id; // Возвращаем ошибку, если не удалось создать пользователя // } // update_user_meta( $user_id, 'billing_email', $email ); // Устанавливаем email // update_user_meta( $user_id, 'user_email', $email ); // Устанавливаем email для входа // // Устанавливаем роль пользователя как 'customer' для WooCommerce // $user = new WP_User( $user_id ); // $user->set_role( 'customer' ); // return $user_id; // } // add_filter( 'woocommerce_add_error', 'remove_payments_word_from_errors_multilang' ); // function remove_payments_word_from_errors_multilang( $error ) { // // Слова для удаления в разных языках // $translations = array( // 'Платежи', // Русский // 'Billing', // Английский // ); // foreach ( $translations as $word ) { // $error = str_replace( $word, '', $error ); // } // return trim( $error ); // } // add_action( 'woocommerce_checkout_process', 'validate_phone_field_with_li_data_id' ); // function validate_phone_field_with_li_data_id() { // // Получаем значение телефона из формы // $phone = isset( $_POST['billing_phone'] ) ? sanitize_text_field( $_POST['billing_phone'] ) : ''; // // Проверяем формат телефона // if ( ! preg_match( '/^\+?[0-9\s\-\(\)]+$/', $phone ) ) { // wc_add_notice( 'phone_err', 'error', 'billing_phone' ); // } // } // add_action('woocommerce_checkout_create_order', 'auto_fill_shipping_fields_from_billing', 10, 1); // function auto_fill_shipping_fields_from_billing( $order_id ) { // // Получаем объект заказа // $order = wc_get_order( $order_id ); // if ( ! $order ) { // return; // Если заказ недоступен, выходим // } // // Получаем значения полей billing из глобального $_POST // $billing_first_name = isset( $_POST['billing_first_name'] ) ? sanitize_text_field( $_POST['billing_first_name'] ) : ''; // $billing_last_name = isset( $_POST['billing_last_name'] ) ? sanitize_text_field( $_POST['billing_last_name'] ) : ''; // $billing_address_1 = isset( $_POST['billing_address_1'] ) ? sanitize_text_field( $_POST['billing_address_1'] ) : ''; // $billing_address_2 = isset( $_POST['billing_address_2'] ) ? sanitize_text_field( $_POST['billing_address_2'] ) : ''; // $billing_city = isset( $_POST['billing_city'] ) ? sanitize_text_field( $_POST['billing_city'] ) : ''; // $billing_postcode = isset( $_POST['billing_postcode'] ) ? sanitize_text_field( $_POST['billing_postcode'] ) : ''; // $billing_country = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : ''; // $billing_state = isset( $_POST['billing_state'] ) ? sanitize_text_field( $_POST['billing_state'] ) : ''; // $billing_phone = isset( $_POST['billing_phone'] ) ? sanitize_text_field( $_POST['billing_phone'] ) : ''; // $billing_email = isset( $_POST['billing_email'] ) ? sanitize_email( $_POST['billing_email'] ) : ''; // // Копируем данные в поля доставки // $order->set_shipping_first_name( $billing_first_name ); // $order->set_shipping_last_name( $billing_last_name ); // $order->set_shipping_address_1( $billing_address_1 ); // $order->set_shipping_address_2( $billing_address_2 ); // $order->set_shipping_city( $billing_city ); // $order->set_shipping_postcode( $billing_postcode ); // $order->set_shipping_country( $billing_country ); // $order->set_shipping_state( $billing_state ); // // Сохраняем изменения в заказе // $order->save(); // } // function custom_checkout_fields( $fields ) { // // Проверяем, находимся ли мы на странице регистрации // if ( isset( $_POST['createaccount'] ) && $_POST['createaccount'] == '1' ) { // // Сделать поле телефона необязательным на этапе регистрации // $fields['billing']['billing_phone']['required'] = false; // } else { // // Убедиться, что поле телефона обязательно при оформлении заказа // $fields['billing']['billing_phone']['required'] = true; // } // return $fields; // } // add_filter( 'woocommerce_checkout_fields', 'custom_checkout_fields' ); //remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 ); // add_filter( 'woocommerce_coupons_enabled', 'coupon_field_on_checkout' ); // function coupon_field_on_checkout( $enabled ) { // return false; // }