Поддержка WooCommerce Не отображаются контактные данные клиента в WooCommerce.

  • Доброго дня.
    У меня возникла проблема с плагином Woocommerce Simplify checkout. Своими простатой и функционалом он меня устроил более чем. Но мне понадобилось добавить пару полей.

    Исходный код у автора на Github.
    https://github.com/systemo-biz/woocommerce-simplify-checkout/

    К сожалению уже тогда я заметил небольшие проблемы в виде того что в панели заказов в админке, поля с адресом доставки, и прочими контактными данными пусты.

    Помогите пожалуйста разобраться, в чём может быть проблема. Если посмотрите на функцию формирующую отправку, то хотя бы billin_email то должен отправляться.

    Мой код.

    Файл woocommerce-simplify-checkout.php
    wp-content/plugins/woocommerce-simplify-checkout-master/woocommerce-simplify-checkout.php

    <?php
    //include 'http://tenera-home.ru/wp-includes/pluggable.php'
    //add_action( 'plugins_loaded');
    
    /*
    	Plugin Name:       Woocommerce Simplify checkout
    	Plugin URI:        https://github.com/systemo-biz/woocommerce-simplify-checkout/
    	Description:       Уменьшает кол-во полей чекаута и переносит в корзину
    	Author:            Александр Павлюков
    	License:           GNU General Public License v2
    	License URI:       http://www.gnu.org/licenses/gpl-2.0.html
    	GitHub Plugin URI: https://github.com/systemo-biz/woocommerce-simplify-checkout/
    	GitHub Branch:     master
    
    	Version:           20160404
    */
    
    // Отключаем выбор типа оплаты
    add_filter('woocommerce_cart_needs_payment', '__return_false');
    
    // Отключаем выбор способа доставки
    add_filter('woocommerce_cart_needs_shipping', '__return_false');
    
    // Убираем ненужные поля
    add_filter( 'woocommerce_checkout_fields' , 'remove_extra_checkout_fields' );
    function remove_extra_checkout_fields( $fields ) {
    
    	unset( $fields['billing']['billing_last_name'] );
    	unset( $fields['billing']['billing_company'] );
    //	unset( $fields['billing']['billing_address_1'] );
    	unset( $fields['billing']['billing_address_2'] );
    	unset( $fields['billing']['billing_city'] );
    	unset( $fields['billing']['billing_postcode'] );
    //	unset( $fields['billing']['billing_country'] );
    	unset( $fields['billing']['billing_state'] );
    	unset( $fields['shipping']['shipping_first_name'] );
    	unset( $fields['shipping']['shipping_last_name'] );
    	unset( $fields['shipping']['shipping_company'] );
    //	unset( $fields['shipping']['shipping_address_1'] );
    	unset( $fields['shipping']['shipping_address_2'] );
    //	unset( $fields['shipping']['shipping_city'] );
    	unset( $fields['shipping']['shipping_postcode'] );
    	unset( $fields['shipping']['shipping_country'] );
    	unset( $fields['shipping']['shipping_state'] );
    	unset( $fields['account']['account_username'] );
    	unset( $fields['account']['account_password'] );
    	unset( $fields['account']['account_password-2'] );
    	unset( $fields['order']['order_comments'] );
    
        return $fields;
    }
    
    // Функция для получения значения опред. поля адреса клиента
    if ( !function_exists( 'get_address_field_value' ) ) {
    	function get_address_field_value($customer_id, $field_name) {
    		$load_address = 'billing';
    		$address = WC()->countries->get_address_fields( get_user_meta( $customer_id, $load_address . '_country', true ), $load_address . '_' );
    
    			foreach ( $address as $key => $field ) {
    				$value = get_user_meta( get_current_user_id(), $key, true );
    				if ( ! $value ) {
    					switch( $key ) {
    						case 'billing_email' :
    						    $current_user = wp_get_current_user();
    							$value = $current_user->user_email;
    						break;
    					}
    				}
    				$address[ $key ]['value'] = apply_filters( 'woocommerce_my_account_edit_address_field_value', $value, $key, $load_address );
    			}
    
    		return ( !empty( $address[$field_name]['value'] ) ) ? $address[$field_name]['value'] : '' ;
    	}
    }
    
    // Убираем из корзины переход в чекаут и ставим свою форму
    add_action( 'woocommerce_cart_collaterals', 'custom_checkout_form', 1 );
    function custom_checkout_form() {
    
    	remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10 );
    
    	load_template( plugin_dir_path( __FILE__ ) . 'templates/form-checkout.php', true );
    
    }
    

    Файл form-checkout.php
    wp-content/plugins/woocommerce-simplify-checkout-master/templates/form-checkout.php

    <?php
    /*
     * 	Custom Checkout Form
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    wc_print_notices();
    
    $checkout = WC()->checkout();
    
    $customer_id = get_current_user_id();
    
    // If checkout registration is disabled and not logged in, the user cannot checkout
    if ( ! $checkout->enable_signup && ! $checkout->enable_guest_checkout && ! is_user_logged_in() ) {
    	echo apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) );
    	return;
    }
    
    ?>
    
    <h2 class="entry-title">Оформление заказа</h2>
    
    <form name="checkout" method="post" class="checkout woocommerce-checkout form-horizontal" action="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" enctype="multipart/form-data">
    
    	<div class="row">
    	    
    		<div class="col-md-4">
    
    			<div class="form-group">
    				<label for="billing_first_name" class="control-label col-md-3"><?php _e( 'First name', 'woocommerce' ); ?></label>
    				<div class="col-md-9">
    					<input type="text" class="input-text form-control" name="billing_first_name" id="billing_firts_name" required="required" placeholder="" value="<?php esc_attr_e( get_address_field_value($customer_id, 'billing_first_name') ); ?>">
    				</div>
    			</div>
    
    			<div class="form-group">
    				<label for="billing_phone" class="control-label col-md-3"><?php _e( 'Phone', 'woocommerce' ); ?></label>
    				<div class="col-md-9">
    					<input type="text" class="input-text form-control" name="billing_phone" id="billing_phone" required="required" placeholder="" value="<?php esc_attr_e( get_address_field_value($customer_id, 'billing_phone') ); ?>">
    				</div>
    			</div>
    
    			<div class="form-group">
    				<label for="billing_email" class="control-label col-md-3"><?php _e( 'Email address', 'woocommerce' ); ?></label>
    				<div class="col-md-9">
    					<input type="email" class="input-text form-control" name="billing_email" id="billing_email" required="required" placeholder="" value="<?php esc_attr_e( get_address_field_value($customer_id, 'billing_email') ); ?>" />
    				</div>
    			</div>
    			
    			<div class="form-group">
    				<label for="billing_country" class="control-label col-md-3">Страна</label>
    				<div class="col-md-9">
    					<input type="text" class="input-text form-control" name="billing_country" id="billing_country" required="required" placeholder="" value="<?php esc_attr_e( get_address_field_value($customer_id, 'billing_country') ); ?>">
    				</div>
    			</div>				
    			
    			<div class="form-group">
    				<label for="shipping_city" class="control-label col-md-3">Город</label>
    				<div class="col-md-9">
    					<input type="text" class="input-text form-control" name="shipping_city" id="shipping_city" required="required" placeholder="" value="<?php esc_attr_e( get_address_field_value($customer_id, 'shipping_city') ); ?>">
    				</div>
    			</div>			
    
    			<div class="form-group">
    				<label for="billing_address_1" class="control-label col-md-3">Адрес</label>
    				<div class="col-md-9">
    					<input type="text" class="input-text form-control" name="billing_address_1" id="billing_address_1" required="required" placeholder="" value="<?php esc_attr_e( get_address_field_value($customer_id, 'billing_address_1') ); ?>">
    				</div>
    			</div>			
    			
    			<div class="form-group">
    				<div class="col-md-9 col-md-offset-3 checkout-submit">
    					<?php wp_nonce_field( 'woocommerce-process_checkout' ); ?>
    					<input type="submit" class="btn btn-submit" name="woocommerce_checkout_place_order" id="place_order" value="Оформить заказ" data-value="Оформить заказ" />
    				</div>
    			</div>
    
    		</div>
    		
    	</div>
    
    </form>
    

    Буду очень признателен за помощь. В случае успеха с удовольствием выложу результат.
    WC 3.1.0
    WP 4.8

    • Тема изменена 6 лет, 9 месяцев назад пользователем SeVlad. Причина: перенос в подходящий раздел
  • Тема «Не отображаются контактные данные клиента в WooCommerce.» закрыта для новых ответов.