Php Woocommerce“;订单付款”;页面-显示帐单地址?

Php Woocommerce“;订单付款”;页面-显示帐单地址?,php,hook-woocommerce,Php,Hook Woocommerce,您如何在“订单付款”页面上显示账单和发货地址,并可能进行修改。(这是可用于请求付款的页面)。您可以通过将以下代码添加到function.php文件(首选使用子主题)来实现这一点,以防止在新更新时删除 if(!is_admin()) { // Function to check starting char of a string function startsWith($haystack, $needle) { return $needle === '' || strpos($haystack,

您如何在“订单付款”页面上显示账单和发货地址,并可能进行修改。(这是可用于请求付款的页面)。

您可以通过将以下代码添加到function.php文件(首选使用子主题)来实现这一点,以防止在新更新时删除

if(!is_admin())
{
// Function to check starting char of a string
function startsWith($haystack, $needle)
{
return $needle === '' || strpos($haystack, $needle) === 0;
}
// Custom function to display the Billing Address form to registration page
function my_custom_function()
{
global $woocommerce;
$checkout = $woocommerce->checkout();
?>
<!–<h3><?php _e( 'Billing Address', 'woocommerce' ); ?></h3>–>
<?php
foreach ($checkout->checkout_fields['billing'] as $key => $field) :
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
endforeach;
}
add_action('register_form','my_custom_function');

// Custom function to save Usermeta or Billing Address of registered user
function save_address($user_id)
{
global $woocommerce;
$address = $_POST;
foreach ($address as $key => $field) :
if(startsWith($key,'billing_'))
{
// Condition to add firstname and last name to user meta table
if($key == 'billing_first_name' || $key == 'billing_last_name')
{
$new_key = explode('billing_',$key);
update_user_meta( $user_id, $new_key[1], $_POST[$key] );
}
update_user_meta( $user_id, $key, $_POST[$key] );
}
endforeach;

}
add_action('woocommerce_created_customer','save_address');

// Registration page billing address form Validation
function custom_validation()
{
global $woocommerce;
$address = $_POST;
foreach ($address as $key => $field) :
// Validation: Required fields
if(startsWith($key,'billing_'))
{
if($key == 'billing_country' && $field == '')
{
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please select a country.', 'woocommerce' ) );
}
if($key == 'billing_first_name' && $field == '')
{
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter first name.', 'woocommerce' ) );
}
if($key == 'billing_last_name' && $field == '')
{
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter last name.', 'woocommerce' ) );
}
if($key == 'billing_address_1' && $field == '')
{
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter address.', 'woocommerce' ) );
}
if($key == 'billing_city' && $field == '')
{
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter city.', 'woocommerce' ) );
}
if($key == 'billing_state' && $field == '')
{
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter state.', 'woocommerce' ) );
}
if($key == 'billing_postcode' && $field == '')
{
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter a postcode.', 'woocommerce' ) );
}
if($key == 'billing_email' && $field == '')
{
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter billing email address.', 'woocommerce' ) );
}
if($key == 'billing_phone' && $field == '')
{
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter phone number.', 'woocommerce' ) );
}

}
endforeach;
}
add_action('register_post','custom_validation');
}
如果(!is_admin())
{
//函数检查字符串的起始字符
使用($haystack,$Pineder)启动函数
{
返回$needle==''| strpos($haystack,$needle)==0;
}
//用于向注册页面显示帐单地址表单的自定义功能
函数my_自定义_函数()
{
全球商业;
$checkout=$woocommerce->checkout();
?>
–>

您好,欢迎光临,Stack Overflow是一个获取编码问题答案的地方。请共享您的代码,以便我们提供帮助!请参阅