首页 文章

如何在Woocommerce的结帐标签中添加自定义字段?

提问于
浏览
1

我可以在这里找到'm using a plugin to create a multi-step checkout cart. It'的文档:http://woocommerce-multistep-checkout.mubashir09.com/documentation/

我已经创建了一个新的标签,如下所示:

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 ,该字段确实显示但位于结算标签顶部而不是之前的标签我需要它 .

1 回答

  • 0

    我只是发现我可以使用jquery从另一侧移动该字段 . 我认为不是最好的解决方案,但确实有效 .

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

相关问题