Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在电子商务签出中设置默认值_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 如何在电子商务签出中设置默认值

Php 如何在电子商务签出中设置默认值,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我刚刚用下面的代码创建了一个带有order review的页面 <form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( $get_checkout_url ); ?>" enctype="multipart/form-data"> <h3 id="order_review_heading"><?php _e(

我刚刚用下面的代码创建了一个带有order review的页面

<form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( $get_checkout_url ); ?>" enctype="multipart/form-data">
<h3 id="order_review_heading"><?php _e( 'Your order', 'woocommerce' ); ?></h3>

    <?php do_action( 'woocommerce_checkout_before_order_review' ); ?>

    <div id="order_review" class="woocommerce-checkout-review-order">
        <?php do_action( 'woocommerce_checkout_order_review' ); ?>
    </div>

    <?php do_action( 'woocommerce_checkout_after_order_review' ); ?></div>
    </form>
    <?php do_action( 'woocommerce_after_checkout_form', $checkout ); ?>
      </div>
但是当我点击结帐按钮时,我得到了错误


国家是必填字段。
名字是必填字段。
姓氏是必填字段。
地址是必填字段。
城镇/城市是必填字段。
州/县是必填字段。
邮政编码/Zip是必填字段。
电子邮件地址是必填字段。
电话是必填字段。


如何在woocommerce签出页面中设置默认值我发现这段代码可能很有用:

<?php
  add_filter( 'woocommerce_checkout_fields' , 'default_values_checkout_fields' );
  function default_values_checkout_fields( $fields ) {
    // You can use this for postcode, address, company, first name, last name and such. 
    $fields['billing']['billing_city']['default'] = 'SomeCity';
    $fields['shipping']['shipping_city']['default'] = 'SomeCity';
         return $fields;
  }
?>

然后使用CSS隐藏输入

参考资料

  • 字段名可以是
  • 主要功能

  • 在字段定义中使用
    default
    custom\u属性
    ,将自定义属性应用于账单/发货地址和帐户字段:


    你有没有把这些价值写进你的结账表?
    <?php
      add_filter( 'woocommerce_checkout_fields' , 'default_values_checkout_fields' );
      function default_values_checkout_fields( $fields ) {
        // You can use this for postcode, address, company, first name, last name and such. 
        $fields['billing']['billing_city']['default'] = 'SomeCity';
        $fields['shipping']['shipping_city']['default'] = 'SomeCity';
             return $fields;
      }
    ?>
    
    add_filter('woocommerce_checkout_fields', 'my_woocommerce_checkout_fields');
    add_filter('woocommerce_billing_fields', 'my_woocommerce_billing_fields');
    
    function my_woocommerce_checkout_fields($fields) {
      $fields['billing'] = my_woocommerce_billing_fields($fields['billing']);
      return $fields;
    }
    
    function my_woocommerce_billing_fields($fields) {
      // Note: Default value is only used if the user account does
      // not have any value for the meta field yet. (Empty value is
      // also a value.) Ensure that the value is set correctly.
      $fields['billing_city']['default'] = 'SomeCity';
    
      // Disable the field in the form.
      // (Note: Does not prevent different values from being posted.)
      $fields['billing_city']['custom_attributes']['readonly'] = TRUE;
      $fields['billing_city']['custom_attributes']['disabled'] = TRUE;
    
      return $fields;
    }