2016-06-08 106 views
1

我使用插件來創建多步結帳購物車。它的文檔可以在這裏找到:http://woocommerce-multistep-checkout.mubashir09.com/documentation/如何將自定義字段添加到Woocommerce的結賬標籤中?

我創建了一個新的標籤,象這樣:

add_action('woocommerce_multistep_checkout_before', 'add_my_custom_step'); 

function add_my_custom_step() { 
    $contents = '<h1>Custom Step</h1>'; 
    $contents .= '<div class="my-custom-step"> Place your step contents here. This can be anything including HTML/PHP </div>'; 
    echo $contents; 
} 

現在我想的是自定義內把步驟一大堆新的領域。我怎樣才能做到這一點?我期待在woocommerce文件,並嘗試這樣的:

//what hook should I use here to put it in the tab I created? 
add_action('woocommerce_multistep_checkout_before', 'my_custom_checkout_field'); 

function my_custom_checkout_field($checkout) { 

    echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>'; 

    woocommerce_form_field('my_field_name', array(
     'type'   => 'text', 
     'class'   => array('my-field-class form-row-wide'), 
     'label'   => __('Fill in this field'), 
     'placeholder' => __('Enter something'), 
     ), $checkout->get_value('my_field_name')); 

    echo '</div>'; 

} 

所以基本上這使得整個頁面爲空。我試圖找出我應該使用什麼鉤子來使該字段出現。如果我使用woocommerce_before_checkout_billing_form該字段確實出現,但在結算標籤的頂部,而不是我需要它的前一個標籤。

回答

0

我剛纔發現我可以使用jquery從另一端移動字段。不是我想的最好的解決方案,但它確實有效。

jQuery(function(){ 
    jQuery(".my-field-class").detach().appendTo(".my-custom-step") 
}) 
相關問題