WooCommerce has recently changed its Checkout page implementation on its newer versions. Hence, the legacy code may not work. You can try downgrading the WooCommerce version or adhering to the latest checkout code.