2016-06-08 104 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") 
}) 
相关问题