6
如何在交貨時在交貨日下方添加自定義textarea字段,以便當您單擊貨到付款單選按鈕時,textarea似乎輸入保存到訂單中的詳細信息?Woocommerce交付貨幣添加自定義字段
如何在交貨時在交貨日下方添加自定義textarea字段,以便當您單擊貨到付款單選按鈕時,textarea似乎輸入保存到訂單中的詳細信息?Woocommerce交付貨幣添加自定義字段
複製checkout/payment-method.php文件到您的主題目錄woocommerce文件夾。即你的主題/ woocommerce /結帳/付款method.php
變化的內容裏標籤用下面的代碼:
<li class="wc_payment_method payment_method_<?php echo $gateway->id; ?>">
<input id="payment_method_<?php echo $gateway->id; ?>" type="radio" class="input-radio" name="payment_method" value="<?php echo esc_attr($gateway->id); ?>" <?php checked($gateway->chosen, true); ?> data-order_button_text="<?php echo esc_attr($gateway->order_button_text); ?>" />
<label for="payment_method_<?php echo $gateway->id; ?>">
<?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?>
</label>
<?php if (($gateway->has_fields() || $gateway->get_description()) && $gateway->id != "cod") : ?>
<div class="payment_box payment_method_<?php echo $gateway->id; ?>" <?php if (! $gateway->chosen) : ?>style="display:none;"<?php endif; ?>>
<?php $gateway->payment_fields(); ?>
</div>
<?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; ?>>
<?php $gateway->payment_fields(); ?>
<label>Custom Field</label>
<input type="text" name='cod_custom_field'>
</div>
<?php endif; ?>
</li>
/**
* 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']));
}
}
/**
* Display field value on the order edit page
*/
add_action('woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1);
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('COD Custom Field').':</strong> ' . get_post_meta($order->id, 'COD Custom Field', true) . '</p>';
}
就是這樣。希望這個幫助。