【问题标题】:Woocommerce - Adding Custom Fields to Checkout & Custom Dashboard TabWoocommerce - 将自定义字段添加到结帐和自定义仪表板选项卡
【发布时间】:2020-06-09 03:38:55
【问题描述】:

我有一个多步骤结帐,因此我创建了一个名为“卡数据”的新自定义步骤,我希望客户在其中填写输入。此输入也应显示在我的帐户中的选项卡上。我已经为我的帐户仪表板创建了一个新的自定义选项卡。 你能告诉我,我如何在结帐过程中创建自定义字段并使其在自定义仪表板选项卡中可见。客户应该可以通过仪表板自行更改数据条目。

非常感谢

【问题讨论】:

  • 你能分享你目前使用的代码吗?这通过调整你的问题

标签: woocommerce product checkout dashboard


【解决方案1】:
// i use multistep checkout wizzard plugin. here i create a step, where user 
enters the card data



add_action('woocommerce_multistep_checkout_before', 'add_visica_step');

function add_visica_step() {
$contents = '<h1>Visica Daten</h1>';
$contents .= '<div class="visica-step"> Please Enter something </div>';
echo $contents;
}


add_filter ( 'woocommerce_account_menu_items', 'one_more_link' );
function one_more_link( $menu_links ){


$new = array( 'carddata' => 'Card Data' );


$menu_links = array_slice( $menu_links, 0, 1, true ) 
+ $new 
+ array_slice( $menu_links, 1, NULL, true );


return $menu_links;
}



/*
* Step 2. Register Permalink Endpoint
*/



add_action( 'init', 'add_endpoint' );
function add_endpoint() {

// WP_Rewrite is my Achilles' heel, so please do not ask me for detailed 
explanation
add_rewrite_endpoint( 'visicadata', EP_PAGES );

}

/* * 第 3 步。我的帐户中新页面的内容,woocommerce_account_{ENDPOINT NAME}_endpoint */

add_action('woocommerce_account_visicadata_endpoint', 'my_account_endpoint_content' ); 函数 my_account_endpoint_content() {

 echo 'Here I want do display custom fields from checkout';

 }




 add_filter( 'woocommerce_checkout_fields' , 

'woocommerce_checkout_field_editor');

// Our hooked in function - $fields is passed via the filter!
 function woocommerce_checkout_field_editor( $fields ) {
 $fields['shipping']['shipping_field_value'] = array(
    'label'     => __('Field Value', 'woocommerce'),
    'placeholder'   => _x('Field Value', 'placeholder', 'woocommerce'),
    'required'  => true
   );

  return $fields;
 }

// Display Field on Order Page, but i would like to display it on custom tab

 add_action( 'woocommerce_admin_order_data_after_shipping_address', 
 'edit_woocommerce_checkout_page', 10, 1 );
 function edit_woocommerce_checkout_page($order){
   global $post_id;
   $order = new WC_Order( $post_id );
   echo '<p><strong>'.__('Field Value').':</strong> ' . get_post_meta($order->get_id(), '_shipping_field_value', true ) . '</p>';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 2018-09-12
    • 1970-01-01
    • 2017-03-21
    • 2023-04-10
    相关资源
    最近更新 更多