我一直在寻找一种解决方案,当选择货到付款选项时,在付款选项区域的结帐页面上显示一个自定义输入字段。选择后,它会显示一个字段,客户在其中输入一个值,并将数据发送到管理订单详细信息页面。这就是我想到的。我在结帐/付款方式中插入了此代码。php
<?php if ( $gateway->has_fields() || /* $gateway->get_description() && */ $gateway->id != "cod" ) : ?>
<?php endif; ?>
<?php if ( $gateway->id == "cod" ) : ?>
<div class="payment_box payment_method_<?php echo $gateway->id; ?>" <?php if ( ! $gateway->chosen ) : ?>style="display:none;"<?php endif; ?>>
<input type="text" name=\'cod_custom_field\' placeholder="Enter Your Margin" >
</div>
<?php endif; ?>
这是结账页面上的样子Checkout COD custom box 完整模板here
这里是驻留在函数中的代码。php
/**
* Update the order meta with field value
*/
add_action( \'woocommerce_checkout_update_order_meta\', \'my_custom_checkout_field_update_order_meta\' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST[\'cod_custom_field\'] ) ) {
update_post_meta( $order_id, \'COD Custom Field\', sanitize_text_field( $_POST[\'cod_custom_field\'] ) );
}
}
/** Field Entry Karne ke liye
* Display field value on the order edit page
*/
add_action( \'woocommerce_admin_order_data_after_shipping_address\', \'my_custom_checkout_field_display_admin_order_meta\', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo \'<p><h2><strong><h2>\'.__(\'Reseller Margin\').\':</h2></strong> \' . get_post_meta( $order->id,\'COD Custom Field\', true ) . \'</h2></p>\';
}
以下是签出页面上的图像当我输入一个值时,它在管理订单详细信息中显示如下内容:Admin Order Details现在,我希望在前端的订单详细信息页面上也显示相同的值。PLz tell me how do I do it? 在这里,我希望输入值显示在“保证金或奖金”标签上Order details page on My account (customers)