I have made some adjustments to my WooCommerce checkout (code that places the discount code elsewhere). It’s working but when this code is added and a customer applies a discount code it removes all the information the customer has already filled out, so that they need to write their name, address, email and phone again.
How do I adjust this code to prevent the data being removed, forcing the customer to enter it twice?
/*
* Removing default "Coupon form" from the top of the checkout page
*/
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
/*
* Hooking "Coupon form" after order total in checkout page with custom function
*/
add_action( 'woocommerce_review_order_after_order_total', 'woocommerce_checkout_coupon_form_custom' );
/*
* Rendering html for "Coupon form" with custom function
*/
function woocommerce_checkout_coupon_form_custom() {
echo '<tr class="coupon-form"><td colspan="2">';
wc_get_template(
'checkout/form-coupon.php',
array(
'checkout' => WC()->checkout(),
)
);
echo '</td></tr>';
}
/* Åben rabatkode felt */
//Tilpas CSS
function mujuonly_add_inline_css() {
$mustlogin_custom_css = "
.woocommerce-form-coupon {
display:block !important;
}
";
//Styling i CSS visningen
wp_add_inline_style( 'woocommerce-inline', $mustlogin_custom_css ); //Variabel videregives til sheet
}
add_action( 'wp_enqueue_scripts', 'mujuonly_add_inline_css' ); //CSS style