问题描述
我正在尝试按顺序存储自定义运输和帐单字段,然后在电子邮件(管理员和客户)中打印,但没有成功,有没有人愿意帮助我? 如您所见,我删除了一些字段,在 Shipping & Billing 中添加了其他字段,然后我尝试存储订单数据,最后我尝试在 order_email 中发送我的额外字段。 这是我在functions.PHP中的代码
// Replace billing_email with shipping_email " This because custome don recieve email notification if don't ask invoice "
add_action('woocommerce_checkout_update_order_Meta','set_billing_email_from_shipping_email',50,2 );
function set_billing_email_from_shipping_email( $order_id,$data ) {
// Get customer shipping email
$email = get_post_meta( $order_id,'_shipping_email',true );
// Set billing email from shipping email
update_post_Meta( $order_id,'_billing_email',$email );
}
// Remove fields
add_filter( 'woocommerce_checkout_fields','wc_remove_checkout_fields' );
function wc_remove_checkout_fields( $fields ) {
// Billing fields
unset( $fields['billing']['billing_first_name'] );
unset( $fields['billing']['billing_last_name'] );
unset( $fields['billing']['billing_address_2'] );
// Shipping fields
unset( $fields['shipping']['shipping_address_2'] );
unset( $fields['shipping']['shipping_company'] );
// Order fields
unset( $fields['order']['order_comments'] );
return $fields;
}
//Add custom fields
add_filter( 'woocommerce_shipping_fields','custom_shipping_fields' );
function custom_shipping_fields( $fields ) {
$fields['shipping_email'] = array(
'label' => __( 'Email','woocommerce' ),'required' =>true,'class' => array( 'form-row-last' ),'validate' => array( 'email' ),);
$fields['shipping_phone'] = array(
'label' => __( 'Telefono','required' => true,'class' => array( 'form-row-first' ),'clear' => true,'validate' => array( 'phone' ),);
$fields['shipping_invoice'] =array(
'type' => 'checkBox','class' => array('form-row-four'),'label' => __(' Fattura ?'),'label_class' => array('woocommerce-form__label l_checkBox'),'input_class' => array('woocommerce-form__input woocommerce-form__input-checkBox i_checkBox'),);
return $fields;
}
add_filter( 'woocommerce_billing_fields','custom_billing_fields' );
function custom_billing_fields( $fields ) {
$fields['billing_vat'] = array(
'label' => __( 'P.Iva/CF','required' =>false,);
return $fields;
};
function custom_shipping_save_extra_checkout_fields( $order_id,$posted ){
if( isset( $posted['custom_shipping_fields'] ) ) {
update_post_Meta( $order_id,'_custom_shipping_fields',sanitize_text_field( $posted['_custom_shipping_fields'] ) );
}
}
function custom_billing_save_extra_checkout_fields( $order_id,sanitize_text_field( $posted['_custom_shipping_fields'] ) );
}
}
add_action( 'woocommerce_checkout_update_order_Meta','custom_save_extra_checkout_fields',10,2 );
function custom_email_order_Meta_fields( $fields,$sent_to_admin,$order ) {
$fields['custom_shipping_fields'] = array(
'label' => __( 'Custom Siping Fields' ),'value' => get_post_meta( $order->id,true ),);
return $fields;
}
add_filter('woocommerce_email_order_Meta_fields','custom_email_order_Meta_fields',3 );
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)